/[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 9 by dpavlin, Thu Aug 20 16:47:46 2009 UTC revision 12 by dpavlin, Mon Nov 2 15:43:01 2009 UTC
# Line 8  my $recepies = 'recepies/'; Line 8  my $recepies = 'recepies/';
8    
9  use File::Find;  use File::Find;
10  use File::Slurp;  use File::Slurp;
11    use File::Path;
12  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
13  use XML::Simple;  use XML::Simple;
14  use Regexp::Common qw /URI/;  use Regexp::Common qw /URI/;
# Line 42  sub file { Line 43  sub file {
43          $path =~ s{^$recepies/*(.*?[^/]+)$}{$1} || next;          $path =~ s{^$recepies/*(.*?[^/]+)$}{$1} || next;
44          return ''          return ''
45                  . qq|<ul class=changes>$changes</ul>|                  . qq|<ul class=changes>$changes</ul>|
46                  . ( $path =~ m{(\.sh|Makefile)$}i ? qq|<a class="path" href="$svn/view/recepies/$path">$path</a>| : '' )                  . ( $path =~ m{(\.sh|Makefile|\.conf)$}i ? qq|<a class="path" href="$svn/view/recepies/$path">$path</a>| : '' )
47                  . qq|<pre class=content>$content</pre>|                  . qq|<pre class=content>$content</pre>|
48                  ;                  ;
49  }  }
# Line 55  find({ follow => 0, no_chdir => 1, wante Line 56  find({ follow => 0, no_chdir => 1, wante
56  my $last_level = 0;  my $last_level = 0;
57  my $toc_html = '';  my $toc_html = '';
58  sub header {  sub header {
59          my ($level, $content) = @_;          my ($level, $name) = @_;
60          my $display = $content;  
61            my $display = $name;
62          $display =~ s{^\d+[\.-]}{};          $display =~ s{^\d+[\.-]}{};
63          $display =~ s{-}{ }g;          $display =~ s{-}{ }g;
64          $display =~ s{\.\w+$}{};          $display =~ s{\.\w+$}{};
65          $content =~ s{\W+}{_}g;  
66          html qq|<a name=$content></a>|;          my $anchor = $name;
67            $anchor =~ s{</?[^>]+>}{}g;
68            $anchor =~ s{\W+}{_}g;
69    
70            html qq|<a name=$anchor></a>|;
71          html qq|<h$level>$display</h$level>|;          html qq|<h$level>$display</h$level>|;
72    
73          if ( $last_level > $level ) {          if ( $last_level > $level ) {
# Line 69  sub header { Line 75  sub header {
75          } elsif ( $last_level < $level ) {          } elsif ( $last_level < $level ) {
76                  $toc_html .= "<ul>";                  $toc_html .= "<ul>";
77          }          }
78          $toc_html .= qq|<li><a href="#$content">$display</li>|;          $toc_html .= qq|<li><a href="#$anchor">$display</li>|;
79          $last_level = $level;          $last_level = $level;
80  }  }
81    
82  my $to_path = '';  my $to_path = '';
83  our @item;  our @item;
84    
85    sub mkfilepath {
86            my $path = shift;
87            $path =~ s{/[^/]+$}{};
88            mkpath $path unless -d $path;
89    }
90    
91  sub new_feed {  sub new_feed {
92          my $name = shift;          my $name = shift;
93          my $feed = XML::FeedPP::RSS->new();          my $feed = XML::FeedPP::RSS->new();
# Line 95  sub add_item { Line 107  sub add_item {
107    
108          my $item_feed = new_feed( $name );          my $item_feed = new_feed( $name );
109          add_feed_item_description($item_feed, $name, "http://sysadmin-cookbook.rot13.org/#$name", $content);          add_feed_item_description($item_feed, $name, "http://sysadmin-cookbook.rot13.org/#$name", $content);
110          $item_feed->to_file("rss/$name.xml");          my $file = "rss/$name.xml";
111            mkfilepath $file;
112            $item_feed->to_file($file);
113    
114          warn "# $name\n";          warn "# $name\n";
115  }  }
# Line 113  foreach my $path ( sort @names ) { Line 127  foreach my $path ( sort @names ) {
127          next if ( -d $path && ! -e "$path/.svn" );          next if ( -d $path && ! -e "$path/.svn" );
128    
129          my $name = $path;          my $name = $path;
130    #       $name =~ s{^$recepies.*?([^/]+)$}{$1} || next;
131          $name =~ s{^$recepies.*?([^/]+)$}{$1} || next;          $name =~ s{^$recepies.*?([^/]+)$}{$1} || next;
132          next unless $name;  
133            my @just_path = split m{/}, $path;
134            @just_path = splice @just_path, 1, -1;
135    
136          if ( -d $path ) {          if ( -d $path ) {
137                  add_item( splice(@item,0) );                  add_item( splice(@item,0) );
138                  header 1,$name;                  my $h1 = join(' ',@just_path);
139                    $h1 = qq|<span class="p">$h1</span> | if $h1;
140                    $h1 .= $name;
141                    header 1, $h1;
142                  $to_path = '';                  $to_path = '';
143                  push @item, $name;                  push @item, $name;
144          } elsif ( -l $path ) {          } elsif ( -l $path ) {
# Line 152  h1 { Line 172  h1 {
172          padding: 0.3em;          padding: 0.3em;
173  }  }
174    
175    h1 .p {
176            color: #888;
177    }
178    
179  .toc {  .toc {
180          font-size: 80%;          font-size: 80%;
181  }  }

Legend:
Removed from v.9  
changed lines
  Added in v.12

  ViewVC Help
Powered by ViewVC 1.1.26