diff options
Diffstat (limited to 'makesite.pl')
-rwxr-xr-x | makesite.pl | 53 |
1 files changed, 49 insertions, 4 deletions
diff --git a/makesite.pl b/makesite.pl index 2b6c7e1..92064c5 100755 --- a/makesite.pl +++ b/makesite.pl @@ -5,6 +5,9 @@ use warnings; use File::Cat; use File::Slurp; use Text::Markdown "markdown"; +use Time::Piece; + +my $BASE_URL="http://blog.vdouillet.fr/"; sub page { my ($pageFile, $pageTitle, $pageContent, $pageType, $id) = @_; @@ -28,11 +31,14 @@ sub page { } print $outHandle $pageContent; print $outHandle "</$pageType>"; + if($pageType eq "article") { + cat "template/back.html", $outHandle; + } cat "template/footer.html", $outHandle; close $outHandle; # Create gzip version - `gzip -k output/$pageFile`; + `gzip -kf output/$pageFile`; } # Build about @@ -57,6 +63,10 @@ while(<*.md>) { my $pageFile = substr $articleFile, 9, -3; $pageFile .= ".html"; + # Extract description + # TODO + my $description = ""; + # Build article my $articleContent = read_file $articleFile; $articleContent = markdown $articleContent; @@ -66,14 +76,49 @@ while(<*.md>) { 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"; + my $articleData = { date => "$month-$day-$year", title => $headLine, address => $pageFile, description => $description }; + push @articleList, $articleData; } # 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 .= $_; +for(my $i = $#articleList; $i >= 0; $i--) { + $indexContent .= "* [$articleList[$i]{date} $articleList[$i]{title}]($articleList[$i]{address} \"$articleList[$i]{title}\")\n"; } $indexContent = markdown $indexContent; page "index.html", "blog.vdouillet.fr", $indexContent, "body", "index-body"; + +# Build RSS feed with article list in reverse (most recent first) +print "Building RSS feed\n"; +open my $outHandle, ">>", "output/rss.xml"; +# Write channel info and insert publication and build dates +open my $inHandle, "<", "template/rss.xml"; +my $pubDate = Time::Piece->strptime($articleList[$#articleList]{date}, "%m-%d-%Y"); # Last article date +$pubDate = $pubDate->strftime(); +my $buildDate = gmtime->strftime(); # Current date +while(<$inHandle>) { + $_ =~ s/\$link/$BASE_URL/; + $_ =~ s/\$pubDate/$pubDate/; + $_ =~ s/\$lastBuildDate/$buildDate/; + print $outHandle $_; +} +close $inHandle; +for(my $i = $#articleList; $i >= 0; $i--) { + open my $inHandle, "<", "template/rss-item.xml"; + my $url = $BASE_URL . $articleList[$i]{address}; + my $pubDate = Time::Piece->strptime($articleList[$i]{date}, "%m-%d-%Y"); + $pubDate = $pubDate->strftime(); + while(<$inHandle>) { + $_ =~ s/\$title/$articleList[$i]{title}/; + $_ =~ s/\$link/$url/; + $_ =~ s/\$description/$articleList[$i]{description}/; + $_ =~ s/\$guid/$articleList[$i]{address}/; + $_ =~ s/\$pubDate/$pubDate/; + print $outHandle $_; + } + close $inHandle; +} +print $outHandle "</channel>\n</rss>\n"; +close $outHandle; + |