X-Git-Url: http://git.rot13.org/?p=sysadmin-cookbook-html;a=blobdiff_plain;f=bin%2Fhtml.pl;h=6039b361b649dd1bd424b7e9e752fc0656902ce3;hp=0a591fafe793b60c92175e68b639da65bc695f88;hb=b356e721222c6504f99da41d51206092e3792b3e;hpb=54c82eb6d404da8cdb0ada498b8b129a93573510;ds=sidebyside diff --git a/bin/html.pl b/bin/html.pl index 0a591fa..6039b36 100755 --- a/bin/html.pl +++ b/bin/html.pl @@ -3,11 +3,13 @@ use warnings; use strict; -my $recepies = '/srv/sysadmin-cookbook/recepies'; +my $recepies = 'recepies/'; use File::Find; use File::Slurp; use Data::Dump qw/dump/; +use XML::Simple; +use Regexp::Common qw /URI/; my @html; sub html { push @html, @_ } @@ -20,15 +22,32 @@ sub file { my $content = read_file $path; $content =~ s{[\n\r\s]+$}{}s; $content =~ s/($escape_re)/$escape{$1}/gs; + $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 '' - . "
    " . `svn log $path` . "
    " - . "
    $content
    " + . 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; @@ -38,6 +57,8 @@ sub header { my $display = $content; $display =~ s{^\d+[\.-]}{}; $display =~ s{-}{ }g; + $display =~ s{\.\w+$}{}; + $content =~ s{\W+}{_}g; html qq||; html qq|$display|; @@ -50,20 +71,25 @@ sub header { $last_level = $level; } +my $to_path = ''; + foreach my $path ( sort @names ) { + next if ( -d $path && ! -e "$path/.svn" ); + my $name = $path; - $name =~ s{^$recepies.*?([^/]+)$}{$1}; + $name =~ s{^$recepies.*?([^/]+)$}{$1} || next; next unless $name; if ( -d $path ) { header 1,$name; + $to_path = ''; } elsif ( -l $path ) { - my $to = readlink $path; - header 2,$name; - html $to; + $to_path = " " . readlink $path; + next; } else { - header 2, $name; + header 2, $name . $to_path; + $to_path = ''; html file( $path ); } @@ -78,15 +104,40 @@ print qq| --> + Creative Commons License + 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)