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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
#!/usr/bin/env perl
use strict;
use warnings;
use File::Cat;
use File::Slurp;
use Text::Markdown "markdown";
sub page {
my ($pageFile, $pageTitle, $pageType, $pageContent) = @_;
open my $outHandle, ">>", "output/$pageFile";
# Write header and insert page title
open my $inHandle, "<", "template/header.html";
while(<$inHandle>) {
$_ =~ s/\$title/$pageTitle/;
print $outHandle $_;
}
close $inHandle;
# Write content and footer
print $outHandle "<$pageType>";
print $outHandle $pageContent;
print $outHandle "</$pageType>";
cat "template/footer.html", $outHandle;
close $outHandle;
# Create gzip version
`gzip -k output/$pageFile`;
}
# Build index
print "Building index\n";
my $pageContent = read_file "template/index.html";
page "index.html", "blog.vdouillet.fr", "body", $pageContent;
# Build about
print "Building about\n";
$pageContent = read_file "static/about.md";
$pageContent = markdown $pageContent;
page "about.html", "About", "body", $pageContent;
# Build articles
while(<*.md>) {
print "Processing $_\n";
# Extract article title from the title in MD article
open my $articleHandle, "<", $_;
my $headLine = <$articleHandle>;
$headLine = substr $headLine, 2;
close $articleHandle;
# Extract output file name: MD file name without the date
my $pageFile = substr $_, 9, -3;
$pageFile .= ".html";
# Build article
my $articleContent = read_file $_;
$articleContent = markdown $articleContent;
page $pageFile, $headLine, "article", $articleContent;
}
|