/[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 1 - (show annotations)
Wed May 13 19:51:26 2009 UTC (14 years, 11 months ago) by dpavlin
File MIME type: text/plain
File size: 1141 byte(s)
create first html rendering of cookbook

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
11 my $in_ul = 0;
12
13 my @html;
14 sub html { push @html, @_ }
15
16 my %escape = ('<'=>'&lt;', '>'=>'&gt;', '&'=>'&amp;', '"'=>'&quot;');
17 my $escape_re = join '|' => keys %escape;
18
19 sub file {
20 my $path = shift;
21 my $content = read_file $path;
22 $content =~ s{[\n\r\s]+$}{}s;
23 $content =~ s/($escape_re)/$escape{$1}/gs;
24 return $content;
25 }
26
27 my @names;
28 find({ follow => 0, no_chdir => 1, wanted => sub {
29 push @names, $_ unless m{/\.};
30 }}, $recepies );
31
32 foreach my $path ( sort @names ) {
33
34 my $name = $path;
35 $name =~ s{^$recepies/*}{};
36
37 if ( -d $path ) {
38 html "</ul>" if $in_ul++;
39 html "<h1>$name</h1><ul>";
40 } elsif ( -l $path ) {
41 my $to = readlink $path;
42 html "<li>$name</li>";
43 } else {
44 html "<li>$name<pre>", file( $path ), "</pre></li>";
45 }
46
47 };
48
49 html "</ul>" if $in_ul;
50
51 print qq|
52 <html><head>
53 <title>Sysadmin Cookbook</title>
54 <!--
55 <link type=text/css rel=stylesheet href="style.css">
56 -->
57 <style type=text/css>
58 pre {
59 background: #eee;
60 }
61 </style>
62 </head><body>
63 |
64 , join("\n", @html)
65 , "</body></html>"
66 ;
67

Properties

Name Value
svn:executable *

  ViewVC Help
Powered by ViewVC 1.1.26