jekylljekyll-bootstrap

RSS feed by category


This is the atom.xml being used by my jekyll-botstrap instance


title: Atom Feed


<?xml version="1.0" encoding="{{ site.charset }}"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>{{ site.title }}</title>
    <link href="{{ site.production_url }}/atom.xml" rel="self" />
    <link href="{{ site.production_url }}" />
    <updated>{{ site.time | date_to_xmlschema }}</updated>
    <id>{{ site.production_url }}</id>
    <author>
        <name>{{ site.author.name }}</name>
        <email>{{ site.author.email }}</email>
    </author>
    {% for post in site.posts %}
    <entry>
        <title>{{ post.title }}</title>
        <link href="{{ site.production_url }}{{ post.url }}"/>
        <updated>{{ post.date | date_to_xmlschema }}</updated>
        <id>{{ site.production_url }}{{ post.id }}</id>
        <content type="html">{{ post.content | xml_escape }}</content>
    </entry>
    {% endfor %}
</feed>

Please help me in creating an atom feed for a special category or tag?


Solution

  • You just need to add some logic after your for statement like this:

    {% for post in site.posts %}
    {% if post.categories contains 'categoryNameHere' %}
    <entry>
            <title>{{ post.title }}</title>
            <link href="{{ site.production_url }}{{ post.url }}"/>
            <updated>{{ post.date | date_to_xmlschema }}</updated>
            <id>{{ site.production_url }}{{ post.id }}</id>
            <content type="html">{{ post.content | xml_escape }}</content>
        </entry>
    {% endif %}
    {% endfor %}
    

    You can create different endpoints like /categoryFeed.xml, /atomFeed.xml, if you want people to be able to get different specific rss.