added Creative Commons Attribution-Noncommercial-Share Alike 3.0 Croatia License
[sysadmin-cookbook-html] / bin / html.pl
index 0a591fa..013077d 100755 (executable)
@@ -8,6 +8,8 @@ my $recepies = '/srv/sysadmin-cookbook/recepies';
 use File::Find;
 use File::Slurp;
 use Data::Dump qw/dump/;
 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, @_ }
 
 my @html;
 sub html { push @html, @_ }
@@ -20,9 +22,25 @@ sub file {
        my $content = read_file $path;
        $content =~ s{[\n\r\s]+$}{}s;
        $content =~ s/($escape_re)/$escape{$1}/gs;
        my $content = read_file $path;
        $content =~ s{[\n\r\s]+$}{}s;
        $content =~ s/($escape_re)/$escape{$1}/gs;
+       $content =~ s[$RE{URI}{HTTP}{-keep}][<a href="$1">$1</a>]gs;
+
+       my $log = XMLin( scalar `svn log --xml $path`,
+               ForceArray => [ 'logentry' ],   
+       );
+       my $changes = join("\n",
+               map {
+                       my $d = $_->{date};
+                       $d =~ s{\.\d+Z}{};
+                       $d =~ s{T}{ };
+                       qq|<li>$_->{msg} <span class="date">$d</span></li>|
+               } @{ $log->{logentry} }
+       );
+
+       $path =~ s{^$recepies/*(.*?[^/]+)$}{$1} || next;
        return ''
        return ''
-               . "<pre class=changes>" . `svn log $path` . "</pre>"
-               . "<pre class=content>$content</pre>"
+               . qq|<ul class=changes>$changes</ul>|
+               . ( $path =~ m{(\.sh|Makefile)$}i ? qq|<a class="path" href="recepies/$path">$path</a>| : '' )
+               . qq|<pre class=content>$content</pre>|
                ;
 }
 
                ;
 }
 
@@ -38,6 +56,8 @@ sub header {
        my $display = $content;
        $display =~ s{^\d+[\.-]}{};
        $display =~ s{-}{ }g;
        my $display = $content;
        $display =~ s{^\d+[\.-]}{};
        $display =~ s{-}{ }g;
+       $display =~ s{\.\w+$}{};
+       $content =~ s{\W+}{_}g;
        html qq|<a name=$content></a>|;
        html qq|<h$level>$display</h$level>|;
 
        html qq|<a name=$content></a>|;
        html qq|<h$level>$display</h$level>|;
 
@@ -50,20 +70,23 @@ sub header {
        $last_level = $level;
 }
 
        $last_level = $level;
 }
 
+my $to_path = '';
+
 foreach my $path ( sort @names ) {
 
        my $name = $path;
 foreach my $path ( sort @names ) {
 
        my $name = $path;
-       $name =~ s{^$recepies.*?([^/]+)$}{$1};
+       $name =~ s{^$recepies.*?([^/]+)$}{$1} || next;
        next unless $name;
 
        if ( -d $path ) {
                header 1,$name;
        next unless $name;
 
        if ( -d $path ) {
                header 1,$name;
+               $to_path = '';
        } elsif ( -l $path ) {
        } elsif ( -l $path ) {
-               my $to = readlink $path;
-               header 2,$name;
-               html $to;
+               $to_path = " " . readlink $path;
+               next;
        } else {
        } else {
-               header 2, $name;
+               header 2, $name . $to_path;
+               $to_path = '';
                html file( $path );
        }
 
                html file( $path );
        }
 
@@ -78,15 +101,37 @@ print qq|
 <link type=text/css rel=stylesheet href="style.css">
 -->
 <style type=text/css>
 <link type=text/css rel=stylesheet href="style.css">
 -->
 <style type=text/css>
+
+h1 {
+       background: #000;
+       color: #fff;
+       padding: 0.3em;
+}
+
+.toc {
+       font-size: 80%;
+}
+
 pre.changes {
        color: #444;
 }
 pre.changes {
        color: #444;
 }
+
 pre.content {
 pre.content {
-       padding: 1em;
+       padding: 0.5em;
+       margin: 1em;
        background: #eee;
 }
        background: #eee;
 }
+
+li .date {
+       font-family: monospace;
+       color: #888;
+       float: right;
+}
+
 </style>
 </head><body>
 </style>
 </head><body>
+       <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/hr/"><img alt="Creative Commons License" style="border-width:0; float: right" src="http://i.creativecommons.org/l/by-nc-sa/3.0/hr/88x31.png" /></a>
+       <span xmlns:dc="http://purl.org/dc/elements/1.1/" href="http://purl.org/dc/dcmitype/Text" property="dc:title" rel="dc:type">Sysadmin Cookbook</span> by <a xmlns:cc="http://creativecommons.org/ns#" href="http://www.rot13.org/~dpavlin/" property="cc:attributionName" rel="cc:attributionURL">Dobrica Pavlinusic</a> is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/hr/">Creative Commons Attribution-Noncommercial-Share Alike 3.0 Croatia License</a>.
        |
        . "<div class=toc>$toc_html</div>"
        , join("\n", @html)
        |
        . "<div class=toc>$toc_html</div>"
        , join("\n", @html)