/[sysadmin-cookbook-html]/bin/html.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /bin/html.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3 - (show annotations)
Wed May 13 20:23:53 2009 UTC (15 years ago) by dpavlin
File MIME type: text/plain
File size: 1772 byte(s)
display nice recepie names

1 #!/usr/bin/perl
2
3 use warnings;
4 use strict;
5
6 my $recepies = '/srv/sysadmin-cookbook/recepies';
7
8 use File::Find;
9 use File::Slurp;
10 use Data::Dump qw/dump/;
11
12 my @html;
13 sub html { push @html, @_ }
14
15 my %escape = ('<'=>'&lt;', '>'=>'&gt;', '&'=>'&amp;', '"'=>'&quot;');
16 my $escape_re = join '|' => keys %escape;
17
18 sub file {
19 my $path = shift;
20 my $content = read_file $path;
21 $content =~ s{[\n\r\s]+$}{}s;
22 $content =~ s/($escape_re)/$escape{$1}/gs;
23 return ''
24 . "<pre class=changes>" . `svn log $path` . "</pre>"
25 . "<pre class=content>$content</pre>"
26 ;
27 }
28
29 my @names;
30 find({ follow => 0, no_chdir => 1, wanted => sub {
31 push @names, $_ unless m{/\.};
32 }}, $recepies );
33
34 my $last_level = 0;
35 my $toc_html = '';
36 sub header {
37 my ($level, $content) = @_;
38 my $display = $content;
39 $display =~ s{^\d+[\.-]}{};
40 $display =~ s{-}{ }g;
41 html qq|<a name=$content></a>|;
42 html qq|<h$level>$display</h$level>|;
43
44 if ( $last_level > $level ) {
45 $toc_html .= "</ul>";
46 } elsif ( $last_level < $level ) {
47 $toc_html .= "<ul>";
48 }
49 $toc_html .= qq|<li><a href="#$content">$display</li>|;
50 $last_level = $level;
51 }
52
53 foreach my $path ( sort @names ) {
54
55 my $name = $path;
56 $name =~ s{^$recepies.*?([^/]+)$}{$1};
57 next unless $name;
58
59 if ( -d $path ) {
60 header 1,$name;
61 } elsif ( -l $path ) {
62 my $to = readlink $path;
63 header 2,$name;
64 html $to;
65 } else {
66 header 2, $name;
67 html file( $path );
68 }
69
70 };
71
72 $toc_html .= "</ul>" foreach ( 1 .. $last_level );
73
74 print qq|
75 <html><head>
76 <title>Sysadmin Cookbook</title>
77 <!--
78 <link type=text/css rel=stylesheet href="style.css">
79 -->
80 <style type=text/css>
81 pre.changes {
82 color: #444;
83 }
84 pre.content {
85 padding: 1em;
86 background: #eee;
87 }
88 </style>
89 </head><body>
90 |
91 . "<div class=toc>$toc_html</div>"
92 , join("\n", @html)
93 , "</body></html>"
94 ;
95

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26