6 my $svn = "http://svn.rot13.org/index.cgi/sysadmin-cookbook";
7 my $recepies = 'recepies/';
12 use Data::Dump qw/dump/;
14 use Regexp::Common qw /URI/;
18 sub html { push @html, @_ }
20 my %escape = ('<'=>'<', '>'=>'>', '&'=>'&', '"'=>'"');
21 my $escape_re = join '|' => keys %escape;
25 my $content = read_file $path;
26 $content =~ s{[\n\r\s]+$}{}s;
27 $content =~ s/($escape_re)/$escape{$1}/gs;
28 $content =~ s[$RE{URI}{HTTP}{-keep}][<a href="$1">$1</a>]gs;
30 my $log = XMLin( scalar `svn log --xml $path`,
31 ForceArray => [ 'logentry' ],
33 my $changes = join("\n",
36 $d =~ s{:\d\d\.\d+Z}{};
38 my $r = $_->{revision};
39 qq|<li>$_->{msg} <a class="date" title="r$r" href="$svn/revision?rev=$r">$d</a></li>|
40 } reverse @{ $log->{logentry} }
43 $path =~ s{^$recepies/*(.*?[^/]+)$}{$1} || next;
44 warn "## path = $path\n";
46 . qq|<ul class=changes>$changes</ul>|
47 . ( $path =~ m{(\.sh|Makefile|\.conf|\.pl)$}i || -x "$recepies/$path" ? qq|<a class="path" href="$svn/view/recepies/$path">$path</a>| : '' )
48 . qq|<pre class=content>$content</pre>|
53 find({ follow => 0, no_chdir => 1, wanted => sub {
54 push @names, $_ unless m{/\.} || m{^\.};
57 warn "## names = ",dump( @names );
62 my ($level, $name, $full_name) = @_;
64 $full_name =~ s{recepies/}{};
65 warn "## header $level $name [$full_name]\n";
68 $display =~ s{^\d+[\.-]}{};
70 $display =~ s{\.\w+$}{};
72 my $anchor = $full_name;
73 $anchor =~ s{</?[^>]+>}{}g;
74 $anchor =~ s{\W+}{_}g;
76 html qq|<a name=$anchor></a>|;
77 html qq|<h$level>$display</h$level>|;
79 if ( $last_level > $level ) {
81 warn "## $last_level > $level toc /ul";
82 } elsif ( $last_level < $level ) {
84 warn "## $last_level < $level toc ul";
86 $toc_html .= qq|<li><a href="#$anchor">$display</li>|;
95 $path =~ s{/[^/]+$}{};
96 mkpath $path unless -d $path;
101 my $feed = XML::FeedPP::RSS->new();
102 $feed->title( "Sysadmin Cookbook" . ( $name ? " :: $name" : '' ) );
103 $feed->link( "http://sysadmin-cookbook.rot13.org/" . ( $name ? "#$name" : '' ) );
104 #$feed->pubDate( "Thu, 23 Feb 2006 14:43:43 +0900" );
108 our $feed_all = new_feed;
111 my $content = join("\n", @_);
112 return unless $name && $content;
114 add_feed_item_description($feed_all, $name, "http://sysadmin-cookbook.rot13.org/rss/$name.xml", $content);
116 my $item_feed = new_feed( $name );
117 add_feed_item_description($item_feed, $name, "http://sysadmin-cookbook.rot13.org/#$name", $content);
118 my $file = "rss/$name.xml";
120 $item_feed->to_file($file);
122 warn "# $name $file\n";
125 sub add_feed_item_description {
126 my ( $feed, $name, $url, $description ) = @_;
127 my $item = $feed->add_item( $url );
128 $item->title( $name );
129 #$item->pubDate( "2006-02-23T14:43:43+09:00" );
130 $item->description( $description );
133 foreach my $path ( sort @names ) {
135 next if ( -d $path && -e "$path/.svn" );
138 # $name =~ s{^$recepies.*?([^/]+)$}{$1} || next;
139 $name =~ s{^$recepies.*?([^/]+)$}{$1} || next;
141 my @just_path = split m{/}, $path;
142 @just_path = splice @just_path, 1, -1;
147 add_item( splice(@item,0) );
148 my $h1 = join(' ',@just_path);
149 $h1 = qq|<span class="p">$h1</span> | if $h1;
154 } elsif ( -l $path ) {
155 $to_path = " " . readlink $path;
158 header 2, $name . $to_path, $path;
160 my $content = file $path;
162 push @item, qq|<h4>$name</h4>\n$content|;
167 $toc_html .= "</ul>" foreach ( 1 .. $last_level );
169 $feed_all->to_file( "rss/index.xml" );
173 <title>Sysadmin Cookbook</title>
175 <link type=text/css rel=stylesheet href="style.css">
177 <style type=text/css>
204 font-family: monospace;
212 <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>
213 <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>.
215 <small><a href="$svn">Source code repository</a></small>
217 . "<div class=toc>$toc_html</div>"