use File::Find;
use File::Slurp;
-
-my $in_ul = 0;
+use Data::Dump qw/dump/;
+use XML::Simple;
+use Regexp::Common qw /URI/;
my @html;
sub html { push @html, @_ }
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}][<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 ''
+ . 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>|
+ ;
}
my @names;
push @names, $_ unless m{/\.};
}}, $recepies );
+my $last_level = 0;
+my $toc_html = '';
+sub header {
+ my ($level, $content) = @_;
+ 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>|;
+
+ if ( $last_level > $level ) {
+ $toc_html .= "</ul>";
+ } elsif ( $last_level < $level ) {
+ $toc_html .= "<ul>";
+ }
+ $toc_html .= qq|<li><a href="#$content">$display</li>|;
+ $last_level = $level;
+}
+
+my $to_path = '';
+
foreach my $path ( sort @names ) {
my $name = $path;
- $name =~ s{^$recepies/*}{};
+ $name =~ s{^$recepies.*?([^/]+)$}{$1} || next;
+ next unless $name;
if ( -d $path ) {
- html "</ul>" if $in_ul++;
- html "<h1>$name</h1><ul>";
+ header 1,$name;
+ $to_path = '';
} elsif ( -l $path ) {
- my $to = readlink $path;
- html "<li>$name</li>";
+ $to_path = " " . readlink $path;
+ next;
} else {
- html "<li>$name<pre>", file( $path ), "</pre></li>";
+ header 2, $name . $to_path;
+ $to_path = '';
+ html file( $path );
}
};
-html "</ul>" if $in_ul;
+$toc_html .= "</ul>" foreach ( 1 .. $last_level );
print qq|
<html><head>
<link type=text/css rel=stylesheet href="style.css">
-->
<style type=text/css>
-pre {
+
+h1 {
+ background: #000;
+ color: #fff;
+ padding: 0.3em;
+}
+
+.toc {
+ font-size: 80%;
+}
+
+pre.changes {
+ color: #444;
+}
+
+pre.content {
+ padding: 0.5em;
+ margin: 1em;
background: #eee;
}
+
+li .date {
+ font-family: monospace;
+ color: #888;
+ float: right;
+}
+
</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>.
+ <br />
+ <small><a href="http://svn.rot13.org/index.cgi/sysadmin-cookbook/">Source code repository</a></small>
|
+ . "<div class=toc>$toc_html</div>"
, join("\n", @html)
, "</body></html>"
;