more debug and unique anchors
[sysadmin-cookbook-html] / bin / html.pl
index 35827eb..e87f1a5 100755 (executable)
@@ -41,9 +41,10 @@ sub file {
        );
 
        $path =~ s{^$recepies/*(.*?[^/]+)$}{$1} || next;
        );
 
        $path =~ s{^$recepies/*(.*?[^/]+)$}{$1} || next;
+warn "## path = $path\n";
        return ''
                . qq|<ul class=changes>$changes</ul>|
        return ''
                . qq|<ul class=changes>$changes</ul>|
-               . ( $path =~ m{(\.sh|Makefile)$}i ? qq|<a class="path" href="$svn/view/recepies/$path">$path</a>| : '' )
+               . ( $path =~ m{(\.sh|Makefile|\.conf|\.pl)$}i || -x "$recepies/$path" ? qq|<a class="path" href="$svn/view/recepies/$path">$path</a>| : '' )
                . qq|<pre class=content>$content</pre>|
                ;
 }
                . qq|<pre class=content>$content</pre>|
                ;
 }
@@ -53,24 +54,36 @@ find({ follow => 0, no_chdir => 1, wanted => sub {
        push @names, $_ unless m{/\.} || m{^\.};
 }}, $recepies );
 
        push @names, $_ unless m{/\.} || m{^\.};
 }}, $recepies );
 
-my $last_level = 0;
-my $toc_html = '';
+warn "## names = ",dump( @names );
+
+our $last_level = 0;
+our $toc_html = '';
 sub header {
 sub header {
-       my ($level, $content) = @_;
-       my $display = $content;
+       my ($level, $name, $full_name) = @_;
+       $full_name ||= $name;
+       $full_name =~ s{recepies/}{};
+       warn "## header $level $name [$full_name]\n";
+
+       my $display = $name;
        $display =~ s{^\d+[\.-]}{};
        $display =~ s{-}{ }g;
        $display =~ s{\.\w+$}{};
        $display =~ s{^\d+[\.-]}{};
        $display =~ s{-}{ }g;
        $display =~ s{\.\w+$}{};
-       $content =~ s{\W+}{_}g;
-       html qq|<a name=$content></a>|;
+
+       my $anchor = $full_name;
+       $anchor =~ s{</?[^>]+>}{}g;
+       $anchor =~ s{\W+}{_}g;
+
+       html qq|<a name=$anchor></a>|;
        html qq|<h$level>$display</h$level>|;
 
        if ( $last_level > $level ) {
                $toc_html .= "</ul>";
        html qq|<h$level>$display</h$level>|;
 
        if ( $last_level > $level ) {
                $toc_html .= "</ul>";
+               warn "## $last_level > $level toc /ul";
        } elsif ( $last_level < $level ) {
                $toc_html .= "<ul>";
        } elsif ( $last_level < $level ) {
                $toc_html .= "<ul>";
+               warn "## $last_level < $level toc ul";
        }
        }
-       $toc_html .= qq|<li><a href="#$content">$display</li>|;
+       $toc_html .= qq|<li><a href="#$anchor">$display</li>|;
        $last_level = $level;
 }
 
        $last_level = $level;
 }
 
@@ -119,7 +132,7 @@ sub add_feed_item_description {
 
 foreach my $path ( sort @names ) {
 
 
 foreach my $path ( sort @names ) {
 
-       next if ( -d $path && -e "$path/.svn" );
+       next if ( -d $path && -e "$path/.svn" );
 
        my $name = $path;
 #      $name =~ s{^$recepies.*?([^/]+)$}{$1} || next;
 
        my $name = $path;
 #      $name =~ s{^$recepies.*?([^/]+)$}{$1} || next;
@@ -128,6 +141,8 @@ foreach my $path ( sort @names ) {
        my @just_path = split m{/}, $path;
        @just_path = splice @just_path, 1, -1;
 
        my @just_path = split m{/}, $path;
        @just_path = splice @just_path, 1, -1;
 
+       warn "## ?? $path";
+
        if ( -d $path ) {
                add_item( splice(@item,0) );
                my $h1 = join(' ',@just_path);
        if ( -d $path ) {
                add_item( splice(@item,0) );
                my $h1 = join(' ',@just_path);
@@ -140,7 +155,7 @@ foreach my $path ( sort @names ) {
                $to_path = " " . readlink $path;
                next;
        } else {
                $to_path = " " . readlink $path;
                next;
        } else {
-               header 2, $name . $to_path;
+               header 2, $name . $to_path, $path;
                $to_path = '';
                my $content = file $path;
                html $content;
                $to_path = '';
                my $content = file $path;
                html $content;