#!/usr/bin/perl use strict; use warnings; use File::Path qw(make_path remove_tree); use Path::Class; use Getopt::Std; # Root in directory. my $dir; my $VERSION = "v0.1"; sub help { print< give you the whole file at once. local $/=undef; open FILE, "styles.css" or die "Cannot open file $!"; my $styles = ; close FILE; return $styles; } sub markdown { my ($file) = @_; my $filename = "$file"; $filename =~ s/\.html$/.md/g; return `markdown "$filename"`; } sub generate_page { my $file = $_[0]; my $sidebar = transverse($dir, $file); my $styles = styles; my $body = markdown $file; my $page = < Deprecated

Deprecated Just coding for fun

$body
EOF ; return $page; } sub generate_link { my ($file, $options) = @_; $options->{hl} = 0 if !exists($options->{hl}); my $path = $file->stringify; my $str = $file->basename; if($path =~ /index\.md$/) { return ""; } # remove the input directory. $path =~ s/^$dir//g; if($file->is_dir()) { $str = "$str/" if $file->is_dir(); } else { $path =~ s/\.md$/.html/g; $str =~ s/\.md$//g; } # Higlight? my $hl = ""; if($options->{hl} eq 1) { $hl = "class='hl'"; } return "
  • $str
  • "; } sub transverse { my ($directory, $file_needed) = @_; my $retval = ""; $retval = "
      "; while(my $file = $directory->next) { my $filename = $file->stringify; # Some conditions next if $filename =~ /(\.|\.\.)$/; next if $filename eq $directory; if($file_needed eq $file or $file_needed->dir eq $filename) { $retval = "$retval" . generate_link($file, { hl => 1 }); } else { $retval = "$retval" . generate_link($file); } if($file->is_dir()) { my $d = $file_needed->dir->stringify; if($file =~ /$d/ and !($d eq $directory)) { $retval = "$retval" . transverse($file, $file_needed); } } } $retval = "$retval
    "; return $retval; } sub run_on { my $mddir = $_[0] || dir($dir); remove_tree $mddir; while(my $file = $mddir->next) { my $outfile = $file->stringify; # Some conditions next if $outfile =~ /(\.|\.\.)$/; next if $outfile eq $mddir; $outfile =~ s/$dir\//out\//g; !($outfile =~ m/^$dir/) or die "$outfile =~ m/$dir/"; if($file->is_dir()) { # make a directory make_path $outfile; run_on($file); next; } $outfile =~ s/md$/html/g; print STDERR "* writing: $outfile\n"; my $contents = generate_page $file; open FD, ">$outfile"; print FD $contents; close FD; } } sub main { my %opts = ( 'v' => 0, 'h' => 0, 'd' => "in" ); getopts('vhd:', \%opts); if($opts{h}) { help; exit 0; } elsif($opts{v}) { version; exit 0; } elsif($opts{d}) { $dir = dir $opts{d}; } run_on dir($dir); } main @ARGV;