3 |
use warnings; |
use warnings; |
4 |
use strict; |
use strict; |
5 |
|
|
6 |
my $recepies = '/srv/sysadmin-cookbook/recepies'; |
my $svn = "http://svn.rot13.org/index.cgi/sysadmin-cookbook"; |
7 |
|
my $recepies = 'recepies/'; |
8 |
|
|
9 |
use File::Find; |
use File::Find; |
10 |
use File::Slurp; |
use File::Slurp; |
11 |
|
use File::Path; |
12 |
use Data::Dump qw/dump/; |
use Data::Dump qw/dump/; |
13 |
use XML::Simple; |
use XML::Simple; |
14 |
use Regexp::Common qw /URI/; |
use Regexp::Common qw /URI/; |
15 |
|
use XML::FeedPP; |
16 |
|
|
17 |
my @html; |
my @html; |
18 |
sub html { push @html, @_ } |
sub html { push @html, @_ } |
36 |
$d =~ s{:\d\d\.\d+Z}{}; |
$d =~ s{:\d\d\.\d+Z}{}; |
37 |
$d =~ s{T}{ }; |
$d =~ s{T}{ }; |
38 |
my $r = $_->{revision}; |
my $r = $_->{revision}; |
39 |
qq|<li>$_->{msg} <a class="date" title="r$r" href="http://svn.rot13.org/index.cgi/sysadmin-cookbook/revision?rev=$r">$d</a></li>| |
qq|<li>$_->{msg} <a class="date" title="r$r" href="$svn/revision?rev=$r">$d</a></li>| |
40 |
} reverse @{ $log->{logentry} } |
} reverse @{ $log->{logentry} } |
41 |
); |
); |
42 |
|
|
43 |
$path =~ s{^$recepies/*(.*?[^/]+)$}{$1} || next; |
$path =~ s{^$recepies/*(.*?[^/]+)$}{$1} || next; |
44 |
|
warn "## path = $path\n"; |
45 |
return '' |
return '' |
46 |
. qq|<ul class=changes>$changes</ul>| |
. qq|<ul class=changes>$changes</ul>| |
47 |
. ( $path =~ m{(\.sh|Makefile)$}i ? qq|<a class="path" href="recepies/$path">$path</a>| : '' ) |
. ( $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>| |
. qq|<pre class=content>$content</pre>| |
49 |
; |
; |
50 |
} |
} |
51 |
|
|
52 |
my @names; |
my @names; |
53 |
find({ follow => 0, no_chdir => 1, wanted => sub { |
find({ follow => 0, no_chdir => 1, wanted => sub { |
54 |
push @names, $_ unless m{/\.}; |
push @names, $_ unless m{/\.} || m{^\.}; |
55 |
}}, $recepies ); |
}}, $recepies ); |
56 |
|
|
57 |
my $last_level = 0; |
warn "## names = ",dump( @names ); |
58 |
my $toc_html = ''; |
|
59 |
|
our $last_level = 0; |
60 |
|
our $toc_html = ''; |
61 |
sub header { |
sub header { |
62 |
my ($level, $content) = @_; |
my ($level, $name, $full_name) = @_; |
63 |
my $display = $content; |
$full_name ||= $name; |
64 |
|
$full_name =~ s{recepies/}{}; |
65 |
|
warn "## header $level $name [$full_name]\n"; |
66 |
|
|
67 |
|
my $display = $name; |
68 |
$display =~ s{^\d+[\.-]}{}; |
$display =~ s{^\d+[\.-]}{}; |
69 |
$display =~ s{-}{ }g; |
$display =~ s{-}{ }g; |
70 |
$display =~ s{\.\w+$}{}; |
$display =~ s{\.\w+$}{}; |
71 |
$content =~ s{\W+}{_}g; |
|
72 |
html qq|<a name=$content></a>|; |
my $anchor = $full_name; |
73 |
|
$anchor =~ s{</?[^>]+>}{}g; |
74 |
|
$anchor =~ s{\W+}{_}g; |
75 |
|
|
76 |
|
html qq|<a name=$anchor></a>|; |
77 |
html qq|<h$level>$display</h$level>|; |
html qq|<h$level>$display</h$level>|; |
78 |
|
|
79 |
if ( $last_level > $level ) { |
if ( $last_level > $level ) { |
80 |
$toc_html .= "</ul>"; |
$toc_html .= "</ul>"; |
81 |
|
warn "## $last_level > $level toc /ul"; |
82 |
} elsif ( $last_level < $level ) { |
} elsif ( $last_level < $level ) { |
83 |
$toc_html .= "<ul>"; |
$toc_html .= "<ul>"; |
84 |
|
warn "## $last_level < $level toc ul"; |
85 |
} |
} |
86 |
$toc_html .= qq|<li><a href="#$content">$display</li>|; |
$toc_html .= qq|<li><a href="#$anchor">$display</li>|; |
87 |
$last_level = $level; |
$last_level = $level; |
88 |
} |
} |
89 |
|
|
90 |
my $to_path = ''; |
my $to_path = ''; |
91 |
|
our @item; |
92 |
|
|
93 |
|
sub mkfilepath { |
94 |
|
my $path = shift; |
95 |
|
$path =~ s{/[^/]+$}{}; |
96 |
|
mkpath $path unless -d $path; |
97 |
|
} |
98 |
|
|
99 |
|
sub new_feed { |
100 |
|
my $name = shift; |
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" ); |
105 |
|
return $feed; |
106 |
|
} |
107 |
|
|
108 |
|
our $feed_all = new_feed; |
109 |
|
sub add_item { |
110 |
|
my $name = shift; |
111 |
|
my $content = join("\n", @_); |
112 |
|
return unless $name && $content; |
113 |
|
|
114 |
|
add_feed_item_description($feed_all, $name, "http://sysadmin-cookbook.rot13.org/rss/$name.xml", $content); |
115 |
|
|
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"; |
119 |
|
mkfilepath $file; |
120 |
|
$item_feed->to_file($file); |
121 |
|
|
122 |
|
warn "# $name $file\n"; |
123 |
|
} |
124 |
|
|
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 ); |
131 |
|
} |
132 |
|
|
133 |
foreach my $path ( sort @names ) { |
foreach my $path ( sort @names ) { |
134 |
|
|
135 |
|
next if ( -d $path && -e "$path/.svn" ); |
136 |
|
|
137 |
my $name = $path; |
my $name = $path; |
138 |
|
# $name =~ s{^$recepies.*?([^/]+)$}{$1} || next; |
139 |
$name =~ s{^$recepies.*?([^/]+)$}{$1} || next; |
$name =~ s{^$recepies.*?([^/]+)$}{$1} || next; |
140 |
next unless $name; |
|
141 |
|
my @just_path = split m{/}, $path; |
142 |
|
@just_path = splice @just_path, 1, -1; |
143 |
|
|
144 |
|
warn "## ?? $path"; |
145 |
|
|
146 |
if ( -d $path ) { |
if ( -d $path ) { |
147 |
header 1,$name; |
add_item( splice(@item,0) ); |
148 |
|
my $h1 = join(' ',@just_path); |
149 |
|
$h1 = qq|<span class="p">$h1</span> | if $h1; |
150 |
|
$h1 .= $name; |
151 |
|
header 1, $h1; |
152 |
$to_path = ''; |
$to_path = ''; |
153 |
|
push @item, $name; |
154 |
} elsif ( -l $path ) { |
} elsif ( -l $path ) { |
155 |
$to_path = " " . readlink $path; |
$to_path = " " . readlink $path; |
156 |
next; |
next; |
157 |
} else { |
} else { |
158 |
header 2, $name . $to_path; |
header 2, $name . $to_path, $path; |
159 |
$to_path = ''; |
$to_path = ''; |
160 |
html file( $path ); |
my $content = file $path; |
161 |
|
html $content; |
162 |
|
push @item, qq|<h4>$name</h4>\n$content|; |
163 |
} |
} |
164 |
|
|
165 |
}; |
}; |
166 |
|
|
167 |
$toc_html .= "</ul>" foreach ( 1 .. $last_level ); |
$toc_html .= "</ul>" foreach ( 1 .. $last_level ); |
168 |
|
|
169 |
|
$feed_all->to_file( "rss/index.xml" ); |
170 |
|
|
171 |
print qq| |
print qq| |
172 |
<html><head> |
<html><head> |
173 |
<title>Sysadmin Cookbook</title> |
<title>Sysadmin Cookbook</title> |
182 |
padding: 0.3em; |
padding: 0.3em; |
183 |
} |
} |
184 |
|
|
185 |
|
h1 .p { |
186 |
|
color: #888; |
187 |
|
} |
188 |
|
|
189 |
.toc { |
.toc { |
190 |
font-size: 80%; |
font-size: 80%; |
191 |
} |
} |
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> |
<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>. |
<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>. |
214 |
<br /> |
<br /> |
215 |
<small><a href="http://svn.rot13.org/index.cgi/sysadmin-cookbook/">Source code repository</a></small> |
<small><a href="$svn">Source code repository</a></small> |
216 |
| |
| |
217 |
. "<div class=toc>$toc_html</div>" |
. "<div class=toc>$toc_html</div>" |
218 |
, join("\n", @html) |
, join("\n", @html) |