aboutsummaryrefslogtreecommitdiff
path: root/template.pl
blob: 747ac7ccb6970af57e536f3c2441760afc586a39 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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";