From c8a6c4eed5011758d8eaa18639cc546b017d922b Mon Sep 17 00:00:00 2001 From: Vincent Douillet Date: Sun, 7 Aug 2022 14:48:37 +0200 Subject: rss feed (missing description) --- Makefile | 9 +++++---- makesite.pl | 53 ++++++++++++++++++++++++++++++++++++++++++++++---- static/favicon.png | Bin 0 -> 1021 bytes template/rss-item.xml | 7 +++++++ template/rss.xml | 13 +++++++++++++ 5 files changed, 74 insertions(+), 8 deletions(-) create mode 100644 static/favicon.png create mode 100644 template/rss-item.xml create mode 100644 template/rss.xml 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 ""; + 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 "\n\n"; +close $outHandle; + diff --git a/static/favicon.png b/static/favicon.png new file mode 100644 index 0000000..d38ee56 Binary files /dev/null and b/static/favicon.png 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 @@ + +$title +$link +$description +$guid +$pubDate + 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 @@ + + +blog.vdouillet.fr +$link +Humble ramblings about IT and occasionally other topics +en-us +$pubDate +$lastBuildDate + +$link/favicon.png +blog.vdouillet.fr +$link + -- cgit v1.2.3