From 0af1b54b628559cca524061dc12875672abe2121 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Wed, 13 May 2009 19:51:26 +0000 Subject: [PATCH] create first html rendering of cookbook git-svn-id: file:///home/dpavlin/private/svn/sysadmin-cookbook-html@1 3e18072f-9615-4e06-9d3a-648eafba3f8d --- bin/html.pl | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100755 bin/html.pl diff --git a/bin/html.pl b/bin/html.pl new file mode 100755 index 0000000..0436565 --- /dev/null +++ b/bin/html.pl @@ -0,0 +1,67 @@ +#!/usr/bin/perl + +use warnings; +use strict; + +my $recepies = '/srv/sysadmin-cookbook/recepies'; + +use File::Find; +use File::Slurp; + +my $in_ul = 0; + +my @html; +sub html { push @html, @_ } + +my %escape = ('<'=>'<', '>'=>'>', '&'=>'&', '"'=>'"'); +my $escape_re = join '|' => keys %escape; + +sub file { + my $path = shift; + my $content = read_file $path; + $content =~ s{[\n\r\s]+$}{}s; + $content =~ s/($escape_re)/$escape{$1}/gs; + return $content; +} + +my @names; +find({ follow => 0, no_chdir => 1, wanted => sub { + push @names, $_ unless m{/\.}; +}}, $recepies ); + +foreach my $path ( sort @names ) { + + my $name = $path; + $name =~ s{^$recepies/*}{}; + + if ( -d $path ) { + html "" if $in_ul++; + html "

$name

" if $in_ul; + +print qq| + +Sysadmin Cookbook + + + + | + , join("\n", @html) + , "" + ; + -- 2.20.1