Skip to content

Instantly share code, notes, and snippets.

@roachhd
Last active October 30, 2021 22:04
Show Gist options
  • Star 20 You must be signed in to star a gist
  • Fork 6 You must be signed in to fork a gist
  • Save roachhd/f664d2cae2da899be3f6 to your computer and use it in GitHub Desktop.
Save roachhd/f664d2cae2da899be3f6 to your computer and use it in GitHub Desktop.
Feed.xml RSS for Jekyll blog on GitHub pages.

Jekyll RSS Feed Templates.

A few Liquid templates to use for rendering RSS feeds for your Jekyll blog. Featuring four kinds of feeds:

  • feed.xml — Renders the 10 most recent posts.
  • feed.category.xml — Only renders posts for a specific category. This example renders posts for a "miscellaneous" category.
  • feed.links.xml — Only contains posts that link to external websites noted by a link variable in the YAML Front Matter. Not a common Jekyll convention, but a good way to generating a linked list.
  • feed.articles.xml — Only showing articles that don't link to external sites; The opposite of feed.links.xml.

How to use

  • Update _config.yml as noted below, or manually replace the variables.
  • Copy one of the xml (ie, feed.xml) files to the root directory of your Jekyll blog.
  • Run jekyll.

In your generated _site folder you should find a properly formatted feed at feed.xml.

Customizing _config.yml

These templates rely on a customized version of _config.yml. The following lines have been added:

name: Your Blog's Name
description: A description for your blog
url: http://your-blog-url.example.com

This makes it easy to reference the title, description and URL for your site in the feed templates using {{ site.name }}, {{ site.description }} and {{ site.url }}. Even if you're not using these feed templates, you might find these variables useful when you're designing your layouts.

Miscellany

  • Note on YAML Front Matter block: The xml files contain a YAML Front Matter block with the line layout: none. This is necessary because Jekyll will not process a page with Liquid unless there is a YAML block at the top of the file.
  • RSS Autodiscovery: If your template is not already setup to do so, make sure the RSS feeds are discoverable by browsers, bots, etc: rssboard.org/rss-autodiscovery
  • Validation: You can use the W3C Validator to make sure your feeds are formatted correctly: http://validator.w3.org/feed/
---
layout: none
---
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>{{ site.name | xml_escape }} - Articles</title>
<description>{% if site.description %}{{ site.description | xml_escape }}{% endif %}</description>
<link>{{ site.url }}</link>
<atom:link href="{{ site.url }}/feed.articles.xml" rel="self" type="application/rss+xml" />
{% for post in site.posts %}
{% unless post.link %}
<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>
{% endunless %}
{% endfor %}
</channel>
</rss>
---
layout: none
---
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>{{ site.name | xml_escape }} - Miscellaneous</title>
<description>Posts categorized as 'miscellaneous'</description>
<link>{{ site.url }}</link>
<atom:link href="{{ site.url }}/feed.category.xml" rel="self" type="application/rss+xml" />
{% for post in site.categories.miscellaneous limit:10 %}
<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>
---
layout: none
---
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>{{ site.name | xml_escape }}</title>
<description>{% if site.description %}{{ site.description | xml_escape }}{% endif %}</description>
<link>{{ site.url }}</link>
<atom:link href="{{ site.url }}/feed.xml" rel="self" type="application/rss+xml" />
{% for post in site.posts limit:10 %}
<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>
@last2win
Copy link

thank you.

@hsayed21
Copy link

awesome ,thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment