From: Dobrica Pavlinusic Date: Thu, 20 Aug 2009 16:47:46 +0000 (+0000) Subject: - generate nice embeddable rss feeds for each recepie X-Git-Url: http://git.rot13.org/?p=sysadmin-cookbook-html;a=commitdiff_plain;h=5ad9b96c8ab2124fc36687107bc594dfb0a4e805;hp=b356e721222c6504f99da41d51206092e3792b3e - generate nice embeddable rss feeds for each recepie - always point to source code repository git-svn-id: file:///home/dpavlin/private/svn/sysadmin-cookbook-html@9 3e18072f-9615-4e06-9d3a-648eafba3f8d --- diff --git a/bin/html.pl b/bin/html.pl index 6039b36..768fce4 100755 --- a/bin/html.pl +++ b/bin/html.pl @@ -3,6 +3,7 @@ use warnings; use strict; +my $svn = "http://svn.rot13.org/index.cgi/sysadmin-cookbook"; my $recepies = 'recepies/'; use File::Find; @@ -10,6 +11,7 @@ use File::Slurp; use Data::Dump qw/dump/; use XML::Simple; use Regexp::Common qw /URI/; +use XML::FeedPP; my @html; sub html { push @html, @_ } @@ -33,14 +35,14 @@ sub file { $d =~ s{:\d\d\.\d+Z}{}; $d =~ s{T}{ }; my $r = $_->{revision}; - qq|
  • $_->{msg} $d
  • | + qq|
  • $_->{msg} $d
  • | } reverse @{ $log->{logentry} } ); $path =~ s{^$recepies/*(.*?[^/]+)$}{$1} || next; return '' . qq|| - . ( $path =~ m{(\.sh|Makefile)$}i ? qq|$path| : '' ) + . ( $path =~ m{(\.sh|Makefile)$}i ? qq|$path| : '' ) . qq|
    $content
    | ; } @@ -72,6 +74,39 @@ sub header { } my $to_path = ''; +our @item; + +sub new_feed { + my $name = shift; + my $feed = XML::FeedPP::RSS->new(); + $feed->title( "Sysadmin Cookbook" . ( $name ? " :: $name" : '' ) ); + $feed->link( "http://sysadmin-cookbook.rot13.org/" . ( $name ? "#$name" : '' ) ); + #$feed->pubDate( "Thu, 23 Feb 2006 14:43:43 +0900" ); + return $feed; +} + +our $feed_all = new_feed; +sub add_item { + my $name = shift; + my $content = join("\n", @_); + return unless $name && $content; + + add_feed_item_description($feed_all, $name, "http://sysadmin-cookbook.rot13.org/rss/$name.xml", $content); + + my $item_feed = new_feed( $name ); + add_feed_item_description($item_feed, $name, "http://sysadmin-cookbook.rot13.org/#$name", $content); + $item_feed->to_file("rss/$name.xml"); + + warn "# $name\n"; +} + +sub add_feed_item_description { + my ( $feed, $name, $url, $description ) = @_; + my $item = $feed->add_item( $url ); + $item->title( $name ); + #$item->pubDate( "2006-02-23T14:43:43+09:00" ); + $item->description( $description ); +} foreach my $path ( sort @names ) { @@ -82,21 +117,27 @@ foreach my $path ( sort @names ) { next unless $name; if ( -d $path ) { + add_item( splice(@item,0) ); header 1,$name; $to_path = ''; + push @item, $name; } elsif ( -l $path ) { $to_path = " " . readlink $path; next; } else { header 2, $name . $to_path; $to_path = ''; - html file( $path ); + my $content = file $path; + html $content; + push @item, qq|

    $name

    \n$content|; } }; $toc_html .= "" foreach ( 1 .. $last_level ); +$feed_all->to_file( "rss/index.xml" ); + print qq| Sysadmin Cookbook @@ -137,7 +178,7 @@ li .date { Creative Commons License Sysadmin Cookbook by Dobrica Pavlinusic is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Croatia License.
    - Source code repository + Source code repository | . "
    $toc_html
    " , join("\n", @html)