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

Diff of /bin/html.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1 by dpavlin, Wed May 13 19:51:26 2009 UTC revision 8 by dpavlin, Sat Aug 15 01:20:45 2009 UTC
# Line 3  Line 3 
3  use warnings;  use warnings;
4  use strict;  use strict;
5    
6  my $recepies = '/srv/sysadmin-cookbook/recepies';  my $recepies = 'recepies/';
7    
8  use File::Find;  use File::Find;
9  use File::Slurp;  use File::Slurp;
10    use Data::Dump qw/dump/;
11  my $in_ul = 0;  use XML::Simple;
12    use Regexp::Common qw /URI/;
13    
14  my @html;  my @html;
15  sub html { push @html, @_ }  sub html { push @html, @_ }
# Line 21  sub file { Line 22  sub file {
22          my $content = read_file $path;          my $content = read_file $path;
23          $content =~ s{[\n\r\s]+$}{}s;          $content =~ s{[\n\r\s]+$}{}s;
24          $content =~ s/($escape_re)/$escape{$1}/gs;          $content =~ s/($escape_re)/$escape{$1}/gs;
25          return $content;          $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                            $d =~ s{:\d\d\.\d+Z}{};
34                            $d =~ s{T}{ };
35                            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            );
39    
40            $path =~ s{^$recepies/*(.*?[^/]+)$}{$1} || next;
41            return ''
42                    . 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                    ;
46  }  }
47    
48  my @names;  my @names;
49  find({ follow => 0, no_chdir => 1, wanted => sub {  find({ follow => 0, no_chdir => 1, wanted => sub {
50          push @names, $_ unless m{/\.};          push @names, $_ unless m{/\.} || m{^\.};
51  }}, $recepies );  }}, $recepies );
52    
53    my $last_level = 0;
54    my $toc_html = '';
55    sub header {
56            my ($level, $content) = @_;
57            my $display = $content;
58            $display =~ s{^\d+[\.-]}{};
59            $display =~ s{-}{ }g;
60            $display =~ s{\.\w+$}{};
61            $content =~ s{\W+}{_}g;
62            html qq|<a name=$content></a>|;
63            html qq|<h$level>$display</h$level>|;
64    
65            if ( $last_level > $level ) {
66                    $toc_html .= "</ul>";
67            } elsif ( $last_level < $level ) {
68                    $toc_html .= "<ul>";
69            }
70            $toc_html .= qq|<li><a href="#$content">$display</li>|;
71            $last_level = $level;
72    }
73    
74    my $to_path = '';
75    
76  foreach my $path ( sort @names ) {  foreach my $path ( sort @names ) {
77    
78            next if ( -d $path && ! -e "$path/.svn" );
79    
80          my $name = $path;          my $name = $path;
81          $name =~ s{^$recepies/*}{};          $name =~ s{^$recepies.*?([^/]+)$}{$1} || next;
82            next unless $name;
83    
84          if ( -d $path ) {          if ( -d $path ) {
85                  html "</ul>" if $in_ul++;                  header 1,$name;
86                  html "<h1>$name</h1><ul>";                  $to_path = '';
87          } elsif ( -l $path ) {          } elsif ( -l $path ) {
88                  my $to = readlink $path;                  $to_path = " " . readlink $path;
89                  html "<li>$name</li>";                  next;
90          } else {          } else {
91                  html "<li>$name<pre>", file( $path ), "</pre></li>";                  header 2, $name . $to_path;
92                    $to_path = '';
93                    html file( $path );
94          }          }
95    
96  };  };
97    
98  html "</ul>" if $in_ul;  $toc_html .= "</ul>" foreach ( 1 .. $last_level );
99    
100  print qq|  print qq|
101  <html><head>  <html><head>
# Line 55  print qq| Line 104  print qq|
104  <link type=text/css rel=stylesheet href="style.css">  <link type=text/css rel=stylesheet href="style.css">
105  -->  -->
106  <style type=text/css>  <style type=text/css>
107  pre {  
108    h1 {
109            background: #000;
110            color: #fff;
111            padding: 0.3em;
112    }
113    
114    .toc {
115            font-size: 80%;
116    }
117    
118    pre.changes {
119            color: #444;
120    }
121    
122    pre.content {
123            padding: 0.5em;
124            margin: 1em;
125          background: #eee;          background: #eee;
126  }  }
127    
128    li .date {
129            font-family: monospace;
130            color: #888;
131            float: right;
132            margin-right: 1em;
133    }
134    
135  </style>  </style>
136  </head><body>  </head><body>
137            <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>
138            <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>.
139            <br />
140            <small><a href="http://svn.rot13.org/index.cgi/sysadmin-cookbook/">Source code repository</a></small>
141          |          |
142            . "<div class=toc>$toc_html</div>"
143          , join("\n", @html)          , join("\n", @html)
144          , "</body></html>"          , "</body></html>"
145          ;          ;

Legend:
Removed from v.1  
changed lines
  Added in v.8

  ViewVC Help
Powered by ViewVC 1.1.26