Search code examples
jekyllgithub-pages

Generate category-specific RSS feed using Jekyll using GitHub pages


I am trying to generate a post category-specific RSS feed for a GitHub Pages Jekyll website.

I understand that the jekyll-feed plugin can generate an RSS feed for all posts, but according to this GitHub Issue, category-specific feeds are not yet supported.

Other approaches to generate a category-specific feed (i.e., here and here are not supported by GitHub Pages because it won't support custom plugins.

Is there a way to generate a category-specific RSS feed using Jekyll with GitHub Pages?


Solution

  • You can just create your own XML or RSS file. For this answer I have used this example to build on. I also used Wikipedia for an example RSS feed.

    filename: categoryname.rss

    ---
    layout: null
    ---
    <?xml version="1.0" encoding="UTF-8" ?>
    <rss version="2.0">
    <channel>
     <title>{{ site.title }}</title>
     <description>{{ site.description }}</description>
     <link>{{ site.url }}</link>
     <lastBuildDate>{{ site.time | date_to_rfc822 }}</lastBuildDate>
     <pubDate>{{ site.time | date_to_rfc822 }}</pubDate>
     <ttl>1800</ttl>
    
     {% for post in site.categories.categoryname %}
     <item>
      <title>{{ post.title }}</title>
      <description>{{ post.description }}</description>
      <link>{{ post.url }}</link>
      <guid isPermaLink="true">{{ site.url }}{{ post.url }}</guid>
      <pubDate>{{ post.date | date_to_rfc822 }}</pubDate>
     </item>
     {% endfor %}
    
    </channel>
    </rss>
    

    The title should be something like: 'mysitenames categoryname archive'. The description could be your category description. Link is the link to the category. The 'lastBuildDate' value could be the date of your last post and 'pubDate' could be the same.

    Please let me know if you have any questions.