summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVincent Douillet <vincent@vdouillet.fr>2022-08-07 14:48:37 +0200
committerVincent Douillet <vincent@vdouillet.fr>2022-08-09 14:21:41 +0200
commitc8a6c4eed5011758d8eaa18639cc546b017d922b (patch)
tree2426e66d8be746b02ba53f7e5e9b7aa2e458feb6
parent8e3ebb113d8b0b0ab34eebb97c3a8a3ac38a92f8 (diff)
rss feed (missing description)
-rw-r--r--Makefile9
-rwxr-xr-xmakesite.pl53
-rw-r--r--static/favicon.pngbin0 -> 1021 bytes
-rw-r--r--template/rss-item.xml7
-rw-r--r--template/rss.xml13
5 files changed, 74 insertions, 8 deletions
diff --git a/Makefile b/Makefile
index c87940d..d79ab3f 100644
--- a/Makefile
+++ b/Makefile
@@ -29,18 +29,19 @@
PERL5LIB=/home/vincent/perl5/lib/perl5
site :
- @PERL5LIB=$(PERL5LIB) ./makesite.pl
+ LANGUAGE=en_US.UTF-8 LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 ./makesite.pl
@echo "Copying static resources"
@cp static/favicon.ico output/
+ @cp static/favicon.png output/
@mkdir -p output/static
@cp static/passthrough/* output/static
@echo "done"
setup :
mkdir -p output
- PERL5LIB=$(PERL5LIB) perl -MCPAN -e"install File::Cat"
- PERL5LIB=$(PERL5LIB) perl -MCPAN -e"install File::Slurp"
- PERL5LIB=$(PERL5LIB) perl -MCPAN -e"install Text::Markdown"
+ perl -MCPAN -e"install File::Cat"
+ perl -MCPAN -e"install File::Slurp"
+ perl -MCPAN -e"install Text::Markdown"
clean :
rm -rf output/*
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;
+
diff --git a/static/favicon.png b/static/favicon.png
new file mode 100644
index 0000000..d38ee56
--- /dev/null
+++ b/static/favicon.png
Binary files differ
diff --git a/template/rss-item.xml b/template/rss-item.xml
new file mode 100644
index 0000000..77b6e88
--- /dev/null
+++ b/template/rss-item.xml
@@ -0,0 +1,7 @@
+<item>
+<title>$title</title>
+<link>$link</link>
+<description>$description</description>
+<guid>$guid</guid>
+<pubDate>$pubDate</pubDate>
+</item>
diff --git a/template/rss.xml b/template/rss.xml
new file mode 100644
index 0000000..4f519ac
--- /dev/null
+++ b/template/rss.xml
@@ -0,0 +1,13 @@
+<rss version="2.0">
+<channel>
+<title>blog.vdouillet.fr</title>
+<link>$link</link>
+<description>Humble ramblings about IT and occasionally other topics</description>
+<language>en-us</language>
+<pubDate>$pubDate</pubDate>
+<lastBuildDate>$lastBuildDate</lastBuildDate>
+<image>
+<url>$link/favicon.png</url>
+<title>blog.vdouillet.fr</title>
+<link>$link</link>
+</image>