weekee

simple static wikis
git clone git://git.garbash.com/alex/weekee
Log | Files | Refs | README

commit f6b8b0274f92991c7523013a8c1a1c194cb434e5
parent 6b65bb4c16ec54b15d6dc3afcb2835d94f5b08b1
Author: alex <alex@garbash.com>
Date:   Mon, 25 Oct 2021 22:56:59 -0400

Add initial Perl version of "weekee the nav-generator"

While the eventual weekee should do _much_ more than just a nav-
generator, I wanted to check-in this initial version that was the
result of pairing with ~anthony as a baseline worth sharing!

Diffstat:
Aweekee | 53+++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 53 insertions(+), 0 deletions(-)

diff --git a/weekee b/weekee @@ -0,0 +1,53 @@ +#!/usr/bin/env perl +# weekee -- given a wiki directory, generate the HTML details index +use strict; +use warnings; + +use File::Basename; + +main(); + +sub main { + die "usage: weekee DIR\n" unless @ARGV; + + my $dir = $ARGV[0]; + die "Argument $dir is not a directory\n" if !-d $dir; + + print("<aside>\n<nav>\n<h2>Weekee Nav</h2>\n"); + descend($dir); + print("</nav>\n</aside>\n"); +} + +# Recursively descend +# for each directory -- new <details> +# for each file, toss in the body +# descend on each directory +sub descend { + my ($dir) = @_; + + my @dirs; + my @files; + + opendir(my $dh, $dir) or die "opendir: $!"; + for my $entry (readdir $dh) { + next if $entry =~ /^\./; + my $path = "$dir/$entry"; + if (-d $path) { + push @dirs, $path; + } else { + push @files, $path; + } + } + closedir($dh) or die "closedir: $!"; + + print("<ul>\n"); + for my $d (@dirs) { + my $b = basename($d); + print("<li><details>\n"); + print("<summary>$b</summary>\n"); + descend($d); + print("</details></li>\n"); + } + print("<li><a href=\"$_\">".basename($_)."</a></li>\n") for @files; + print("</ul>\n"); +}