diff options
author | Vincent Douillet <vincent@vdouillet.fr> | 2022-05-26 18:49:59 +0200 |
---|---|---|
committer | Vincent Douillet <vincent@vdouillet.fr> | 2022-05-26 18:49:59 +0200 |
commit | 5490f1fd18fcc445f0c48a1ed830678e0f69ac0f (patch) | |
tree | ab8b5aac10b5d8f441f73ddad29817ddee4263ad /makesite.pl | |
parent | d1f761415a8598b1acc162b4c7665ed8c6ad2c3e (diff) |
switch to perl script to make the site
Diffstat (limited to 'makesite.pl')
-rwxr-xr-x | makesite.pl | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/makesite.pl b/makesite.pl new file mode 100755 index 0000000..6980da8 --- /dev/null +++ b/makesite.pl @@ -0,0 +1,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; +} |