Getting a Category Feed Up and Running with Jekyll on Github

Now that I have the site up and running, I am now trying to add a few category specific RSS feeds. I will say that for someone who is new to RSS (i.e. me) the feeds on Wordpress are really easy. But, since I now fancy myself somewhat of hacker, I suppose figuring out how to get a Jekyll site hosted on Github to spit these out is something I should do.

This site is built on the Hyde theme which includes an atom.xml file. This is great and provides a feed for the entire blog but, often a category specific feed is required. For instance, my (poorly named) old blog Landscape Ecology 2.0 has been referenced by a couple of aggregators, most notably R-bloggers. Since I do blog about topics other than R, I need to be able to submit a feed that is specific to R. Wordpress does this automatically with Categories. You can also do this in Jekyll with a little work.

As it turns out many others have had this same need and there are a few options for getting it set up. Since my blog already has a site wide RSS feed built with Liquid templating all I needed was a category specifc one. So I simpl ammended the template from @snaptortoise jekyll-rss-feeds. For my blog, the template looks like:

---
layout: none
---
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
  	<title>{{ site.title | xml_escape }} - r</title>
		<description>Posts categorized as 'r'</description>
		<link>{{ site.url }}</link>
		<atom:link href="{{ site.url }}/feed.r.xml" rel="self" type="application/rss+xml" />
    {% for post in site.categories.r limit:20 %}
      <item>
        <title>{{ post.title | xml_escape }}</title>
        <description>{{ post.content | xml_escape }}</description>
        <pubDate>{{ post.date | date: "%a, %d %b %Y %H:%M:%S %z" }}</pubDate>
        <link>{{ site.url }}{{ post.url }}</link>
        <guid isPermaLink="true">{{ site.url }}{{ post.url }}</guid>
      </item>
    {% endfor %}
	</channel>
</rss>

I have saved this in the source of my website as feed.r.xml. One gotcha is that Jekyll appears to convert all categories to lower case. I had it set to loop on site.categories.R and it wasn’t working. Switching to site.categories.r fixed the problem.

Since feed.r.xml has the layout: null in the YAML, everytime the site builds on Github (i.e. everytime a change is made), this feed will get updated. In theory, I should be able to submit this feed to R-bloggers and everytime I have a new post with the R category, it will also get picked up by R-bloggers. Only downside to this is that a new category template will be required for each category that I want to build the RSS feed for.

NOTE: Getting the Liquid templating to be highlighted in this post also took some work as the the Liquid was getting interpreted, not highlighted. Turns out it is as easy as wrapping the code with:

{% raw %}
{% endraw %}

This answer courtesy of StackOverflow

ANOTHER NOTE: And now to get even more into the weeds, getting {% raw %} to render took another approach, raw HTML. So that looks like

<p>
  <code>&#123;% raw %}</code>
  <br>
  <code>&#123;% endraw %}</code>
</p> 

That answer provided by SLaks.Blog.

Colophon: jwhollister.com v0.2.0

Hard to believe that in less than a year I am now on the third version of my website. First one was me hacking at bootstrap. I knew next to nothing then, but was able to get a minimal site up and running. Since then I have learned quite a bit more about web design, Jekyll, hosting on github, and am a much better hacker than I was then (although still not a good one). My second site never really saw the light of day and was developed from scratch for a web design course I took.

This third site is now being built with Jekyll, hosted on Github, and uses a slightly customized version of the Hyde theme. Hyde is released under the MIT license, and the content on my website is freely available via Creatitve Commons Zero Public Domain Declaration. I would have used WTFPL v2.0, but some might take offense.

I will likely keep hacking on this site by adding some additional styling components and content (i.e. my CV). I do also plan on blogging some here when I get the time. I expect to maintain my old blog as an archive but new content will go here. Any technical changes will be added to this post.