/[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

Annotation of /bin/html.pl

Parent Directory Parent Directory | Revision Log Revision Log


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

1 dpavlin 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 dpavlin 2 use Data::Dump qw/dump/;
11 dpavlin 1
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 dpavlin 2 return ''
24     . "<pre class=changes>" . `svn log $path` . "</pre>"
25     . "<pre class=content>$content</pre>"
26     ;
27 dpavlin 1 }
28    
29     my @names;
30     find({ follow => 0, no_chdir => 1, wanted => sub {
31     push @names, $_ unless m{/\.};
32     }}, $recepies );
33    
34 dpavlin 2 my $last_level = 0;
35     my $toc_html = '';
36     sub header {
37     my ($level, $content) = @_;
38 dpavlin 3 my $display = $content;
39     $display =~ s{^\d+[\.-]}{};
40     $display =~ s{-}{ }g;
41 dpavlin 2 html qq|<a name=$content></a>|;
42 dpavlin 3 html qq|<h$level>$display</h$level>|;
43 dpavlin 2
44     if ( $last_level > $level ) {
45     $toc_html .= "</ul>";
46     } elsif ( $last_level < $level ) {
47     $toc_html .= "<ul>";
48     }
49 dpavlin 3 $toc_html .= qq|<li><a href="#$content">$display</li>|;
50 dpavlin 2 $last_level = $level;
51     }
52    
53 dpavlin 1 foreach my $path ( sort @names ) {
54    
55     my $name = $path;
56 dpavlin 2 $name =~ s{^$recepies.*?([^/]+)$}{$1};
57     next unless $name;
58 dpavlin 1
59     if ( -d $path ) {
60 dpavlin 2 header 1,$name;
61 dpavlin 1 } elsif ( -l $path ) {
62     my $to = readlink $path;
63 dpavlin 2 header 2,$name;
64     html $to;
65 dpavlin 1 } else {
66 dpavlin 2 header 2, $name;
67     html file( $path );
68 dpavlin 1 }
69    
70     };
71    
72 dpavlin 2 $toc_html .= "</ul>" foreach ( 1 .. $last_level );
73 dpavlin 1
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 dpavlin 2 pre.changes {
82     color: #444;
83     }
84     pre.content {
85     padding: 1em;
86 dpavlin 1 background: #eee;
87     }
88     </style>
89     </head><body>
90     |
91 dpavlin 2 . "<div class=toc>$toc_html</div>"
92 dpavlin 1 , join("\n", @html)
93     , "</body></html>"
94     ;
95    

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26