#!/usr/bin/env perl use strict; use warnings; use File::Cat; use File::Slurp; use Text::Markdown "markdown"; sub page { my ($pageFile, $pageTitle, $pageContent, $pageType, $id) = @_; unless(defined $pageType) { $pageType = "body"; # default page type } 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 if(defined $id) { print $outHandle "<$pageType id=\"$id\">"; } else { print $outHandle "<$pageType>"; } print $outHandle $pageContent; print $outHandle ""; cat "template/footer.html", $outHandle; close $outHandle; # Create gzip version `gzip -k output/$pageFile`; } # Build about print "Building about\n"; my $aboutContent = read_file "static/about.md"; $aboutContent = markdown $aboutContent; page "about.html", "About", $aboutContent; # Build articles my @articleList; while(<*.md>) { my $articleFile = $_; print "Processing $articleFile\n"; # Extract article title from the title in MD article open my $articleHandle, "<", $articleFile; my $headLine = <$articleHandle>; $headLine = substr $headLine, 2, -1; close $articleHandle; # Extract output file name: MD file name without the date my $pageFile = substr $articleFile, 9, -3; $pageFile .= ".html"; # Build article my $articleContent = read_file $articleFile; $articleContent = markdown $articleContent; page $pageFile, $headLine, $articleContent, "article"; # Add article to index my $year = substr $articleFile, 0, 4; my $month = substr $articleFile, 4, 2; my $day = substr $articleFile, 6, 2; push @articleList, "* [$month-$day-$year $headLine]($pageFile \"$headLine\")\n"; } # Build index with article list in reverse (most recent first) print "Building index\n"; my $indexContent = read_file "static/index.md"; foreach(reverse @articleList) { $indexContent .= $_; } $indexContent = markdown $indexContent; page "index.html", "blog.vdouillet.fr", $indexContent, "body", "index-body";