/[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 5 by dpavlin, Sat May 16 22:19:40 2009 UTC
# Line 7  my $recepies = '/srv/sysadmin-cookbook/r Line 7  my $recepies = '/srv/sysadmin-cookbook/r
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+Z}{};
34                            $d =~ s{T}{ };
35                            qq|<li>$_->{msg} <span class="date">$d</span></li>|
36                    } @{ $log->{logentry} }
37            );
38    
39            $path =~ s{^$recepies/*(.*?[^/]+)$}{$1} || next;
40            return ''
41                    . qq|<ul class=changes>$changes</ul>|
42                    . ( $path =~ m{(\.sh|Makefile)$}i ? qq|<a class="path" href="recepies/$path">$path</a>| : '' )
43                    . qq|<pre class=content>$content</pre>|
44                    ;
45  }  }
46    
47  my @names;  my @names;
# Line 29  find({ follow => 0, no_chdir => 1, wante Line 49  find({ follow => 0, no_chdir => 1, wante
49          push @names, $_ unless m{/\.};          push @names, $_ unless m{/\.};
50  }}, $recepies );  }}, $recepies );
51    
52    my $last_level = 0;
53    my $toc_html = '';
54    sub header {
55            my ($level, $content) = @_;
56            my $display = $content;
57            $display =~ s{^\d+[\.-]}{};
58            $display =~ s{-}{ }g;
59            $display =~ s{\.\w+$}{};
60            $content =~ s{\W+}{_}g;
61            html qq|<a name=$content></a>|;
62            html qq|<h$level>$display</h$level>|;
63    
64            if ( $last_level > $level ) {
65                    $toc_html .= "</ul>";
66            } elsif ( $last_level < $level ) {
67                    $toc_html .= "<ul>";
68            }
69            $toc_html .= qq|<li><a href="#$content">$display</li>|;
70            $last_level = $level;
71    }
72    
73    my $to_path = '';
74    
75  foreach my $path ( sort @names ) {  foreach my $path ( sort @names ) {
76    
77          my $name = $path;          my $name = $path;
78          $name =~ s{^$recepies/*}{};          $name =~ s{^$recepies.*?([^/]+)$}{$1} || next;
79            next unless $name;
80    
81          if ( -d $path ) {          if ( -d $path ) {
82                  html "</ul>" if $in_ul++;                  header 1,$name;
83                  html "<h1>$name</h1><ul>";                  $to_path = '';
84          } elsif ( -l $path ) {          } elsif ( -l $path ) {
85                  my $to = readlink $path;                  $to_path = " " . readlink $path;
86                  html "<li>$name</li>";                  next;
87          } else {          } else {
88                  html "<li>$name<pre>", file( $path ), "</pre></li>";                  header 2, $name . $to_path;
89                    $to_path = '';
90                    html file( $path );
91          }          }
92    
93  };  };
94    
95  html "</ul>" if $in_ul;  $toc_html .= "</ul>" foreach ( 1 .. $last_level );
96    
97  print qq|  print qq|
98  <html><head>  <html><head>
# Line 55  print qq| Line 101  print qq|
101  <link type=text/css rel=stylesheet href="style.css">  <link type=text/css rel=stylesheet href="style.css">
102  -->  -->
103  <style type=text/css>  <style type=text/css>
104  pre {  
105    h1 {
106            background: #000;
107            color: #fff;
108            padding: 0.3em;
109    }
110    
111    .toc {
112            font-size: 80%;
113    }
114    
115    pre.changes {
116            color: #444;
117    }
118    
119    pre.content {
120            padding: 0.5em;
121            margin: 1em;
122          background: #eee;          background: #eee;
123  }  }
124    
125    li .date {
126            font-family: monospace;
127            color: #888;
128            float: right;
129    }
130    
131  </style>  </style>
132  </head><body>  </head><body>
133            <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>
134            <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>.
135          |          |
136            . "<div class=toc>$toc_html</div>"
137          , join("\n", @html)          , join("\n", @html)
138          , "</body></html>"          , "</body></html>"
139          ;          ;

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

  ViewVC Help
Powered by ViewVC 1.1.26