#!/usr/bin/perl use v5.38; use strict; use warnings; use experimental 'signatures'; use local::lib; use File::Path qw(make_path remove_tree); use Path::Class; use Getopt::Long; # Root in directory. our $indir; our $outdir; my $VERSION = "v0.1"; my @exlude_files = ( qr/log\/\w+\/*/ ); my $with_sidebar = 1; sub help { print< give you the whole file at once. local $/=undef; open my $FILE, '<', "styles.css" or die "Cannot open file $!"; my $styles = <$FILE>; 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 = ""; if($with_sidebar) { $sidebar = transverse($indir, $file); } my $styles = styles; my $body = markdown($file); my $page = < Deprecated

Deprecated Coding for fun

$body
EOF ; return $page; } sub generate_link { my ($file, $options) = @_; $options->{hl} = 0 if !exists($options->{hl}); # Exclude links if ($file) { if (grep /^$file$/, @exlude_files) { say "excluding $file"; return ""; } my $path = $file->stringify; my $str = $file->basename; if($path =~ /index\.md$/) { return ""; } # remove the input directory. $path =~ s/^$indir//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 ($dirname, $file_needed) = @_; my $retval = ""; my $directory = dir($dirname); $retval = ""; return $retval; } sub run_on { my $dirname = $_[0] or die "Cannot stat input directory"; my $mddir = dir($dirname); while(my $file = $mddir->next) { my $outfile = $file->stringify; # Some conditions: # 1) next if file is . or .. # 2) next if outfile = directory with markdown # 3) die if the output file is in the input directory. next if $outfile eq $mddir; next if $outfile =~ m/(\.|\.\.)($|\/)/; $outfile =~ s/^$indir/$outdir\//g; $outfile !~ m/^$indir/ or die "trying to write in the same directory $outfile"; if($file->is_dir()) { # make a directory make_path $outfile; run_on($file); next; } $outfile =~ s/md$/html/g; # This file it's just for pretty print print STDERR "* writing: " . file($outfile) . "\n"; my $contents = generate_page $file; open my $FD, '>', "$outfile" or die " [ERROR] cannot open > $outfile: $!";; print $FD $contents or die " [ERROR] Cannot write $outfile: $!"; close $FD or die " [ERROR] Cannot close $outfile: $!"; } } sub main { my $help; my $version; my $output_path = 'site.static/'; my $sidebar = 1; GetOptions(help => \$help, version => \$version, "output-path=s", \$output_path, "sidebar" => \$sidebar) or die "Error in command line arguments\n"; $indir = shift @ARGV; if($help) { help; exit 0; } elsif ($version) { version(); exit 0; } if (-d $output_path) { print STDERR "Removing $output_path\n"; remove_tree($output_path); } $outdir = $output_path; mkdir $output_path; run_on $indir; } main;