I Finally Have an RSS Feed

Subscribe to my RSS feed at this link. Full post content included.

That's all. Bye now.

For those who stuck around:

Custom Static Site Generator Part II

As explained in this post, this site is powered by my custom hacky SSG. So I had to do some more scripting to implement this new RSS feed generator. It's really simple as expected (and as the name implies), I just had to adjust some of my original code so that it could be reused, and fill in some XML templates:

cat <<-EOF
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title>~jlucas/</title>
		<link>${url}/</link>
		<description>Posts by jlucas</description>
		<language>en-us</language>
		<lastBuildDate>$(date -Rd "${posts%%-*}")</lastBuildDate>
		<atom:link href="${url}/index.xml" rel="self" type="application/rss+xml" />
		$(items)
	</channel>
</rss>
EOF

This is the outer template. Mostly all constants except for the lastBuildDate tag, which I am formatting based on the date prefix of the latest post, which happens to be the first entry in the space separated $posts variable.

The template for the actual posts is expanded from the items function, which simply fills in another template in a loop:

for fname in $posts; do
	cat <<-EOF
	<item>
		<title>$(gettitle "${srcdir}/posts/${fname}")</title>
		<link>${url}/posts/${fname%md}html</link>
		<pubDate>$(date -Rd "${fname%%-*}")</pubDate>
		<guid>${url}/posts/${fname%md}html</guid>
		<description><![CDATA[
			$(tail +3 "${srcdir}/posts/${fname}" | render)
		]]></description>
	</item>
	EOF
done

The gettitle function was explained in part 1, and the render function simply wraps the code to preprocess and convert the markdown content to HTML.

Then just add it to the Makefile and it's done:

index.xml: $(POSTS) $(SCRIPTS)
	src/ssg/genrss.sh > $@

You can check out the full code here.

Expect a Part III whenever I manage to integrate some nice (static, server side) syntax highlighting to fix those ugly code blocks.