6 my $recepies = '/srv/sysadmin-cookbook/recepies';
10 use Data::Dump qw/dump/;
12 use Regexp::Common qw /URI/;
15 sub html { push @html, @_ }
17 my %escape = ('<'=>'<', '>'=>'>', '&'=>'&', '"'=>'"');
18 my $escape_re = join '|' => keys %escape;
22 my $content = read_file $path;
23 $content =~ s{[\n\r\s]+$}{}s;
24 $content =~ s/($escape_re)/$escape{$1}/gs;
25 $content =~ s[$RE{URI}{HTTP}{-keep}][<a href="$1">$1</a>]gs;
27 my $log = XMLin( scalar `svn log --xml $path`,
28 ForceArray => [ 'logentry' ],
30 my $changes = join("\n",
35 qq|<li>$_->{msg} <span class="date">$d</span></li>|
36 } @{ $log->{logentry} }
39 $path =~ s{^$recepies/*(.*?[^/]+)$}{$1} || next;
41 . qq|<ul class=changes>$changes</ul>|
42 . ( $path =~ m{(\.sh|Makefile)$}i ? qq|<a class="path" href="recepies/$path">$path</a>| : '' )
43 . qq|<pre class=content>$content</pre>|
48 find({ follow => 0, no_chdir => 1, wanted => sub {
49 push @names, $_ unless m{/\.};
55 my ($level, $content) = @_;
56 my $display = $content;
57 $display =~ s{^\d+[\.-]}{};
59 $display =~ s{\.\w+$}{};
60 $content =~ s{\W+}{_}g;
61 html qq|<a name=$content></a>|;
62 html qq|<h$level>$display</h$level>|;
64 if ( $last_level > $level ) {
66 } elsif ( $last_level < $level ) {
69 $toc_html .= qq|<li><a href="#$content">$display</li>|;
75 foreach my $path ( sort @names ) {
78 $name =~ s{^$recepies.*?([^/]+)$}{$1} || next;
84 } elsif ( -l $path ) {
85 $to_path = " " . readlink $path;
88 header 2, $name . $to_path;
95 $toc_html .= "</ul>" foreach ( 1 .. $last_level );
99 <title>Sysadmin Cookbook</title>
101 <link type=text/css rel=stylesheet href="style.css">
103 <style type=text/css>
125 font-family: monospace;
133 . "<div class=toc>$toc_html</div>"