diff options
| author | lemurianmage <azureazure@disroot.org> | 2026-06-13 17:24:45 +0200 |
|---|---|---|
| committer | lemurianmage <azureazure@disroot.org> | 2026-06-13 17:24:45 +0200 |
| commit | 3782f2e533b0a5e517e2e4074db166c8d65dc8cd (patch) | |
| tree | 13cdac30ae3e8e51ae784bd3fd7ed238377af85a /template.pl | |
| parent | 7da42c6e577f49ad4981f24c833b2e1d86357e0b (diff) | |
| download | slimegirl.nexus-3782f2e533b0a5e517e2e4074db166c8d65dc8cd.tar.gz | |
buttons
Diffstat (limited to 'template.pl')
| -rwxr-xr-x | template.pl | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/template.pl b/template.pl index 747ac7c..651d7aa 100755 --- a/template.pl +++ b/template.pl @@ -1,15 +1,16 @@ #!/usr/bin/env perl -# this script is generally responsible for all html postprocessing that md2html can't do +# this script is generally responsible for all html postprocessing use v5.39; use utf8; use autodie; use Mojo::DOM; +use File::Basename; my $template = do { - local $/ = undef; + local $/; open my $fh, '<', 'template.html'; <$fh>; }; @@ -17,16 +18,26 @@ my $template = do { my $dom = Mojo::DOM->new($template); my $content = `md2html $ARGV[0]`; + # inject content @ <article> -$dom->at('article')->append_content($content); +$dom->at('article')->content($content); # replace <title> with the contents of the first <h1> +# also append a <hr> after the first <h1> my $title_dom = $dom->at('h1'); $dom->at('title')->content($title_dom->text) if ($title_dom); +$title_dom->append('<hr>'); + +# makes the up button go up a directory +my $parent = dirname $ARGV[0]; +$parent =~ s/^(?:.+?)(\/.*)/$1/; +$parent = dirname $parent if (basename($ARGV[0]) eq 'index.md' or $parent eq "src"); +$dom->at('#go-up')->attr(href => $parent); +# give title the same contents as alt if it exists for my $img ($dom->find('img')->each) { my $alt = $img->attr('alt'); - $img->attr(title => $alt); + $img->attr(title => $alt) if ($alt); } say "$dom"; |
