X-Git-Url: http://git.rot13.org/?p=sysadmin-cookbook-html;a=blobdiff_plain;f=bin%2Fhtml.pl;h=0b0d8e2d248ffd0b1979a4f08999b2e0c330125e;hp=0436565491e81c5aed5f44af5d5e90db2afe0fda;hb=6162dd22a7d08579ca796ae0b68008d1b9877774;hpb=0af1b54b628559cca524061dc12875672abe2121
diff --git a/bin/html.pl b/bin/html.pl
index 0436565..0b0d8e2 100755
--- a/bin/html.pl
+++ b/bin/html.pl
@@ -3,12 +3,16 @@
use warnings;
use strict;
-my $recepies = '/srv/sysadmin-cookbook/recepies';
+my $svn = "http://svn.rot13.org/index.cgi/sysadmin-cookbook";
+my $recepies = 'recepies/';
use File::Find;
use File::Slurp;
-
-my $in_ul = 0;
+use File::Path;
+use Data::Dump qw/dump/;
+use XML::Simple;
+use Regexp::Common qw /URI/;
+use XML::FeedPP;
my @html;
sub html { push @html, @_ }
@@ -21,32 +25,138 @@ sub file {
my $content = read_file $path;
$content =~ s{[\n\r\s]+$}{}s;
$content =~ s/($escape_re)/$escape{$1}/gs;
- return $content;
+ $content =~ s[$RE{URI}{HTTP}{-keep}][$1]gs;
+
+ my $log = XMLin( scalar `svn log --xml $path`,
+ ForceArray => [ 'logentry' ],
+ );
+ my $changes = join("\n",
+ map {
+ my $d = $_->{date};
+ $d =~ s{:\d\d\.\d+Z}{};
+ $d =~ s{T}{ };
+ my $r = $_->{revision};
+ qq|
$_->{msg} $d|
+ } reverse @{ $log->{logentry} }
+ );
+
+ $path =~ s{^$recepies/*(.*?[^/]+)$}{$1} || next;
+ return ''
+ . qq||
+ . ( $path =~ m{(\.sh|Makefile)$}i ? qq|$path| : '' )
+ . qq|$content
|
+ ;
}
my @names;
find({ follow => 0, no_chdir => 1, wanted => sub {
- push @names, $_ unless m{/\.};
+ push @names, $_ unless m{/\.} || m{^\.};
}}, $recepies );
+my $last_level = 0;
+my $toc_html = '';
+sub header {
+ my ($level, $name) = @_;
+
+ my $display = $name;
+ $display =~ s{^\d+[\.-]}{};
+ $display =~ s{-}{ }g;
+ $display =~ s{\.\w+$}{};
+
+ my $anchor = $name;
+ $anchor =~ s{?[^>]+>}{}g;
+ $anchor =~ s{\W+}{_}g;
+
+ html qq||;
+ html qq|$display|;
+
+ if ( $last_level > $level ) {
+ $toc_html .= "";
+ } elsif ( $last_level < $level ) {
+ $toc_html .= "";
+ }
+ $toc_html .= qq|- $display
|;
+ $last_level = $level;
+}
+
+my $to_path = '';
+our @item;
+
+sub mkfilepath {
+ my $path = shift;
+ $path =~ s{/[^/]+$}{};
+ mkpath $path unless -d $path;
+}
+
+sub new_feed {
+ my $name = shift;
+ my $feed = XML::FeedPP::RSS->new();
+ $feed->title( "Sysadmin Cookbook" . ( $name ? " :: $name" : '' ) );
+ $feed->link( "http://sysadmin-cookbook.rot13.org/" . ( $name ? "#$name" : '' ) );
+ #$feed->pubDate( "Thu, 23 Feb 2006 14:43:43 +0900" );
+ return $feed;
+}
+
+our $feed_all = new_feed;
+sub add_item {
+ my $name = shift;
+ my $content = join("\n", @_);
+ return unless $name && $content;
+
+ add_feed_item_description($feed_all, $name, "http://sysadmin-cookbook.rot13.org/rss/$name.xml", $content);
+
+ my $item_feed = new_feed( $name );
+ add_feed_item_description($item_feed, $name, "http://sysadmin-cookbook.rot13.org/#$name", $content);
+ my $file = "rss/$name.xml";
+ mkfilepath $file;
+ $item_feed->to_file($file);
+
+ warn "# $name\n";
+}
+
+sub add_feed_item_description {
+ my ( $feed, $name, $url, $description ) = @_;
+ my $item = $feed->add_item( $url );
+ $item->title( $name );
+ #$item->pubDate( "2006-02-23T14:43:43+09:00" );
+ $item->description( $description );
+}
+
foreach my $path ( sort @names ) {
+ next if ( -d $path && ! -e "$path/.svn" );
+
my $name = $path;
- $name =~ s{^$recepies/*}{};
+# $name =~ s{^$recepies.*?([^/]+)$}{$1} || next;
+ $name =~ s{^$recepies.*?([^/]+)$}{$1} || next;
+
+ my @just_path = split m{/}, $path;
+ @just_path = splice @just_path, 1, -1;
if ( -d $path ) {
- html "
" if $in_ul++;
- html "$name
";
+ add_item( splice(@item,0) );
+ my $h1 = join(' ',@just_path);
+ $h1 = qq|$h1 | if $h1;
+ $h1 .= $name;
+ header 1, $h1;
+ $to_path = '';
+ push @item, $name;
} elsif ( -l $path ) {
- my $to = readlink $path;
- html "- $name
";
+ $to_path = " " . readlink $path;
+ next;
} else {
- html "- $name
", file( $path ), "
";
+ header 2, $name . $to_path;
+ $to_path = '';
+ my $content = file $path;
+ html $content;
+ push @item, qq|$name
\n$content|;
}
};
-html "
" if $in_ul;
+$toc_html .= "" foreach ( 1 .. $last_level );
+
+$feed_all->to_file( "rss/index.xml" );
print qq|
@@ -55,12 +165,46 @@ print qq|
-->
+
+ Sysadmin Cookbook by Dobrica Pavlinusic is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Croatia License.
+
+ Source code repository
|
+ . "$toc_html
"
, join("\n", @html)
, ""
;