/[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 7 - (hide annotations)
Mon May 18 19:15:05 2009 UTC (15 years, 1 month ago) by dpavlin
File MIME type: text/plain
File size: 3524 byte(s)
make dates link to correct revision

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 4 use XML::Simple;
12     use Regexp::Common qw /URI/;
13 dpavlin 1
14     my @html;
15     sub html { push @html, @_ }
16    
17     my %escape = ('<'=>'&lt;', '>'=>'&gt;', '&'=>'&amp;', '"'=>'&quot;');
18     my $escape_re = join '|' => keys %escape;
19    
20     sub file {
21     my $path = shift;
22     my $content = read_file $path;
23     $content =~ s{[\n\r\s]+$}{}s;
24     $content =~ s/($escape_re)/$escape{$1}/gs;
25 dpavlin 4 $content =~ s[$RE{URI}{HTTP}{-keep}][<a href="$1">$1</a>]gs;
26    
27     my $log = XMLin( scalar `svn log --xml $path`,
28     ForceArray => [ 'logentry' ],
29     );
30     my $changes = join("\n",
31     map {
32     my $d = $_->{date};
33 dpavlin 7 $d =~ s{:\d\d\.\d+Z}{};
34 dpavlin 4 $d =~ s{T}{ };
35 dpavlin 7 my $r = $_->{revision};
36     qq|<li>$_->{msg} <a class="date" title="r$r" href="http://svn.rot13.org/index.cgi/sysadmin-cookbook/revision?rev=$r">$d</a></li>|
37     } reverse @{ $log->{logentry} }
38 dpavlin 4 );
39    
40     $path =~ s{^$recepies/*(.*?[^/]+)$}{$1} || next;
41 dpavlin 2 return ''
42 dpavlin 4 . qq|<ul class=changes>$changes</ul>|
43     . ( $path =~ m{(\.sh|Makefile)$}i ? qq|<a class="path" href="recepies/$path">$path</a>| : '' )
44     . qq|<pre class=content>$content</pre>|
45 dpavlin 2 ;
46 dpavlin 1 }
47    
48     my @names;
49     find({ follow => 0, no_chdir => 1, wanted => sub {
50     push @names, $_ unless m{/\.};
51     }}, $recepies );
52    
53 dpavlin 2 my $last_level = 0;
54     my $toc_html = '';
55     sub header {
56     my ($level, $content) = @_;
57 dpavlin 3 my $display = $content;
58     $display =~ s{^\d+[\.-]}{};
59     $display =~ s{-}{ }g;
60 dpavlin 4 $display =~ s{\.\w+$}{};
61     $content =~ s{\W+}{_}g;
62 dpavlin 2 html qq|<a name=$content></a>|;
63 dpavlin 3 html qq|<h$level>$display</h$level>|;
64 dpavlin 2
65     if ( $last_level > $level ) {
66     $toc_html .= "</ul>";
67     } elsif ( $last_level < $level ) {
68     $toc_html .= "<ul>";
69     }
70 dpavlin 3 $toc_html .= qq|<li><a href="#$content">$display</li>|;
71 dpavlin 2 $last_level = $level;
72     }
73    
74 dpavlin 4 my $to_path = '';
75    
76 dpavlin 1 foreach my $path ( sort @names ) {
77    
78     my $name = $path;
79 dpavlin 4 $name =~ s{^$recepies.*?([^/]+)$}{$1} || next;
80 dpavlin 2 next unless $name;
81 dpavlin 1
82     if ( -d $path ) {
83 dpavlin 2 header 1,$name;
84 dpavlin 4 $to_path = '';
85 dpavlin 1 } elsif ( -l $path ) {
86 dpavlin 4 $to_path = " " . readlink $path;
87     next;
88 dpavlin 1 } else {
89 dpavlin 4 header 2, $name . $to_path;
90     $to_path = '';
91 dpavlin 2 html file( $path );
92 dpavlin 1 }
93    
94     };
95    
96 dpavlin 2 $toc_html .= "</ul>" foreach ( 1 .. $last_level );
97 dpavlin 1
98     print qq|
99     <html><head>
100     <title>Sysadmin Cookbook</title>
101     <!--
102     <link type=text/css rel=stylesheet href="style.css">
103     -->
104     <style type=text/css>
105 dpavlin 4
106     h1 {
107     background: #000;
108     color: #fff;
109     padding: 0.3em;
110     }
111    
112     .toc {
113     font-size: 80%;
114     }
115    
116 dpavlin 2 pre.changes {
117     color: #444;
118     }
119 dpavlin 4
120 dpavlin 2 pre.content {
121 dpavlin 5 padding: 0.5em;
122     margin: 1em;
123 dpavlin 1 background: #eee;
124     }
125 dpavlin 4
126     li .date {
127     font-family: monospace;
128     color: #888;
129     float: right;
130 dpavlin 7 margin-right: 1em;
131 dpavlin 4 }
132    
133 dpavlin 1 </style>
134     </head><body>
135 dpavlin 5 <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>
136     <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>.
137 dpavlin 6 <br />
138     <small><a href="http://svn.rot13.org/index.cgi/sysadmin-cookbook/">Source code repository</a></small>
139 dpavlin 1 |
140 dpavlin 2 . "<div class=toc>$toc_html</div>"
141 dpavlin 1 , join("\n", @html)
142     , "</body></html>"
143     ;
144    

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26