aboutsummaryrefslogtreecommitdiff
path: root/template.pl
diff options
context:
space:
mode:
Diffstat (limited to 'template.pl')
-rwxr-xr-xtemplate.pl32
1 files changed, 32 insertions, 0 deletions
diff --git a/template.pl b/template.pl
new file mode 100755
index 0000000..747ac7c
--- /dev/null
+++ b/template.pl
@@ -0,0 +1,32 @@
+#!/usr/bin/env perl
+
+# this script is generally responsible for all html postprocessing that md2html can't do
+
+use v5.39;
+use utf8;
+use autodie;
+
+use Mojo::DOM;
+
+my $template = do {
+ local $/ = undef;
+ open my $fh, '<', 'template.html';
+ <$fh>;
+};
+
+my $dom = Mojo::DOM->new($template);
+
+my $content = `md2html $ARGV[0]`;
+# inject content @ <article>
+$dom->at('article')->append_content($content);
+
+# replace <title> with the contents of the first <h1>
+my $title_dom = $dom->at('h1');
+$dom->at('title')->content($title_dom->text) if ($title_dom);
+
+for my $img ($dom->find('img')->each) {
+ my $alt = $img->attr('alt');
+ $img->attr(title => $alt);
+}
+
+say "$dom";