From: Tobias Leich Date: Sun, 15 Nov 2009 20:34:40 +0000 (+0100) Subject: tools X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=4e1ad99d1b08ee2b487c3c7bbf60e0abe502c054;p=sdlgit%2FSDL-Site.git tools --- diff --git a/tools/PM-Pod2html-snippet.pl b/tools/PM-Pod2html-snippet.pl new file mode 100644 index 0000000..816558f --- /dev/null +++ b/tools/PM-Pod2html-snippet.pl @@ -0,0 +1,59 @@ +#!/usr/bin/env perl + +use strict; +use warnings; + +use File::Spec; +use Pod::Xhtml; + +#system('git pull'); + +my $input_path = 'C:/SDL_perl/lib/pods'; +my $output_path = 'F:/htdocs/SDL-Site/pages'; +my $parser = Pod::Xhtml->new(FragmentOnly => 1); +my %module_names = (); +my $fh; + +read_file($input_path); + +# creating index file +open($fh, '>', File::Spec->catfile($output_path, 'documentation.html-inc')); +binmode($fh, ":utf8"); +print($fh "
\n

Documentation (latest development branch)

"); +for my $module_name (sort keys %module_names) +{ + print($fh '', + $module_name, + '
' + ); +} +print($fh "
\n"); +close($fh); + +sub read_file +{ + my $path = shift; + my @files = <$path/*>; + + foreach(@files) + { + read_file($_) if(-d $_); + + if($_ =~ /\.pod$/i) + { + my $file_name = $_; + $file_name =~ s/^$input_path\/*//; + my $module_name = $file_name; + $module_name =~ s/\//::/g; + $module_name =~ s/(\.pm|\.pod)$//i; + $file_name =~ s/\//-/g; + $file_name =~ s/(\.pm|\.pod)$/.html-inc/i; + my $file_path = $file_name; + $file_path =~ s/\-inc$//; + $module_names{$module_name} = $file_path; + $file_name = File::Spec->catfile($output_path, $file_name); + + $parser->parse_from_file($_, $file_name); + } + } +} diff --git a/tools/RSS2html-snippet.pl b/tools/RSS2html-snippet.pl new file mode 100644 index 0000000..5a5b59e --- /dev/null +++ b/tools/RSS2html-snippet.pl @@ -0,0 +1,139 @@ +#!/usr/bin/env perl + +use strict; +use warnings; +use utf8; + +use File::Spec::Functions qw(rel2abs splitpath splitdir catpath catdir catfile canonpath); +use XML::Feed; + +my $feed = XML::Feed->parse(URI->new('http://yapgh.blogspot.com/feeds/posts/default?alt=rss')) + or die XML::Feed->errstr; + +my ($volume, $dirs) = splitpath(rel2abs(__FILE__)); + +my @directories = splitdir(canonpath($dirs)); +pop(@directories); +my $parent_dir = catpath($volume, catdir(@directories)); +my $output_path = catdir($parent_dir, 'pages'); + +die("Error: Output path '$output_path' not found.") unless(-d $output_path); + +my $fh; +my %available_tags = (); # tags to filenames +my %tag_overview = (); # tags to short content + +printf("path for placing files is: %s\n", $output_path); + +my $i = 1; +for my $entry ($feed->entries) +{ + my $output_file = sprintf("blog-%04d.html-inc", $i); + my @tags = $entry->tags; + + foreach my $tag (sort @tags) + { + @{$available_tags{$tag}} = () unless defined ($available_tags{$tag}); + push(@{$available_tags{$tag}}, $output_file); + } + + open($fh, '>', catfile($output_path, $output_file)); + binmode($fh, ":utf8"); + print($fh "
\n

\n", + $entry->title, + "\n

\n
\n", + $entry->content->body, + "
", + "
" + ); + close($fh); + + printf("created file: %s\n", $output_file); + + $i++; +} + +open($fh, '>', catfile($output_path, 'blog-0000.html-inc')); +binmode($fh, ":utf8"); +print($fh "

Articles

\n"); +$i = 1; +for my $entry ($feed->entries) +{ + my $tag_links = ''; + my @tags = $entry->tags; + foreach my $tag (sort @tags) + { + my $_tag = $tag; + $_tag =~ s/\W/-/g; + $tag_links .= sprintf(' [%s]', $_tag, $tag); + } + + my $text = $entry->content->body; + $text = $1 if $text =~ /^(.+)$/; + $text =~ s//\n/g; + $text =~ s/<[@#%\w\s"\/?&=:\-\.;']+>/ /g; + $text =~ s/^\n*//g; + $text =~ s/\n*$//g; + $text =~ s/\n+/\n/g; + $text =~ s/\n/
/g; + $text = $1 if $text =~ /^([^<>]+
[^<>]+
[^<>]+
).*$/; + $text =~ s/(
)+$//g; + + # overview of all blog entries + printf($fh '
' + . '%s
' + . '%s
' + . 'Tags:%s
' + . '%s
[more]

' + . '
' + . '
', + $i, $entry->title, $entry->issued->strftime('%A, %d %B %Y'), $tag_links, $text, $i + ); + + # preparing the %tag_overview hash for tag-overview-pages + @tags = $entry->tags; + foreach my $tag (sort @tags) + { + @{$tag_overview{$tag}} = () unless defined ($tag_overview{$tag}); + push(@{$tag_overview{$tag}}, + sprintf('
' + . '%s
' + . '%s
' + . 'Tags: %s
' + . '%s
[more]

' + . '
', + $i, $entry->title, $entry->issued->strftime('%A, %d %B %Y'), $tag_links, $text, $i + )); + } + + $i++; +} +print($fh "
\n"); +close($fh); +printf("created file: %s\n", 'blog-0000.html-inc'); + + +# csv: "tagname: file1,file2\n" +open($fh, '>', catfile($output_path, 'tags-index')); +binmode($fh, ":utf8"); +foreach my $tag (sort keys %available_tags) +{ + printf($fh "%s: %s\n", $tag, join(',', @{$available_tags{$tag}})); +} +close($fh); +printf("created file: %s\n", 'tags-index'); + +# overview pages for tags +foreach my $tag (sort keys %tag_overview) +{ + my $_tag = $tag; + $_tag =~ s/\W/-/g; + open($fh, '>', catfile($output_path, 'tags-' . $_tag . '.html-inc')); + binmode($fh, ":utf8"); + print($fh '

Results for tag: ' . $tag . '

' + . join('
', @{$tag_overview{$tag}}) + . '
'); + close($fh); + printf("created file: %s\n", 'tags-' . $_tag . '.html-inc'); +} +