Insert an RSS or Atom feed on the Jekyll site
In the blogging section, keeping your audience engaged and informed is crucial. One of the most effective ways to do this is with an RSS feed. This simple tool acts as a direct line of communication between your site and your readers, providing readers with instant updates whenever you publish new content.
This guide covers how to add an RSS feed to your Jekyll site, exploring two approaches: Using Jekyll’s Liquid code or the Jekyll-feed plugin. While the plugin offers a streamlined and reliable approach, understanding the underlying mechanics through Liquid empowers you with deeper knowledge and customization options.
By the end of this guide, you’ll know how to choose the best method and keep your readers updated on your latest posts.
This is an example of a simple RSS feed:
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>RSS Feed Exmple</title>
<description>RSS is a fascinating technology. The uses for RSS are expanding daily.</description>
<link>http://www.feedforall.com/industry-solutions.htm</link>
<item>
<title>RSS Solutions for Restaurants</title>
<description>FeedForAll helps Restaurants communicate with customers. Let your customers know the latest specials or events.</description>
<link>http://www.feedforall.com/restaurant.htm</link>
<comments>http://www.feedforall.com/forum</comments>
<pubDate>Tue, 19 Oct 2004 11:09:11 -0400</pubDate>
</item>
<item>
<title>RSS Solutions for Schools and Colleges</title>
<description>FeedForAll helps Educational Institutions communicate with students about school wide activities, events, and schedules</description>
<link>http://www.feedforall.com/schools.htm</link>
<comments>http://www.feedforall.com/forum</comments>
<pubDate>Tue, 19 Oct 2004 11:09:09 -0400</pubDate>
</item>
</channel>
</rss>
However, this instructional writing on inserting an RSS or Atom feed on the Jekyll site will help you deeply understand. Please follow the two methods below to find the best solution for you.
How to insert an RSS or Atom feed on the Jekyll site
Method 1: Using Liquid
In specific, by using Liquid you are able to output an XML file with this format for the site. To begin, you need to create /feed.xml
with the content given below:
---
layout: null
---
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>Bakery Store - Articles</title>
<description>Your latest baking news</description>
<link>{{ site.url }}</link>
{% for post in site.posts %}
{% unless post.draft %}
<item>
<title>{{ post.title | xml_escape }}</title>
<description>{{ post.content | xml_escape }}</description>
<pubDate>{{ post.date | date_to_xmlschema }}</pubDate>
<link>{{ post.url | prepend: site.url }}</link>
<guid isPermaLink="true">{{ post.url | prepend: site.url }}</guid>
</item>
{% endunless %}
{% endfor %}
</channel>
</rss>
This will loop over the blog posts and output metadata in a format of RSS XML. There could be a variable site.url
not defined yet but you could define it in _config.yml
.
...
url: http://bakery-store.example.com
...
To end the process, please add a link to the RSS fwwd to <head>
in _layouts/default.html
.
...
<link rel="alternate" type="application/rss+xml" title="Bakery Store RSS" href="/feed.xml">
...
Now you can see the full feed when you go to /feed.xml
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>Bakery Store - Articles</title>
<description>Your latest baking news</description>
<link>http://bakery-store.example.com</link>
<item>
<title>Where Did The Cookie Come From</title>
<description><p>The chocolate chip cookie was invented by Ruth Graves Wakefield. She owned the Toll House Inn, in Whitman, Massachusetts, a very popular restaurant that featured home cooking in the 1930s. Her cookbook, Toll House Tried and True Recipes, was first published in 1936 by M. Barrows &amp; Company, New York. The 1938 edition of the cookbook was the first to include the recipe “Toll House Chocolate Crunch Cookie” which rapidly became a favorite cookie in American homes.</p>
<p>Source / Read more <a href="https://en.wikipedia.org/wiki/Chocolate_chip_cookie">Wikipedia</a></p>
</description>
<pubDate>2016-01-02T00:00:00+13:00</pubDate>
<link>http://bakery-store.example.com/information/2016/01/02/where-did-the-cookie-come-from.html</link>
<guid isPermaLink="true">http://bakery-store.example.com/information/2016/01/02/where-did-the-cookie-come-from.html</guid>
</item>
<item>
<title>What Is Sour Dough</title>
<description><p>Sourdough bread is made by the fermentation of dough using naturally-occurring lactobacilli and yeast. Sourdough bread has a mildly sour taste not present in most breads made with baker’s yeast and better inherent keeping qualities than other breads, due to the lactic acid produced by the lactobacilli.</p>
<p>Source / Read more <a href="https://en.wikipedia.org/wiki/Sourdough">Wikipedia</a></p>
</description>
<pubDate>2016-01-01T00:00:00+13:00</pubDate>
<link>http://bakery-store.example.com/information/2016/01/01/what-is-sour-dough.html</link>
<guid isPermaLink="true">http://bakery-store.example.com/information/2016/01/01/what-is-sour-dough.html</guid>
</item>
</channel>
</rss>
Method 2: Jekyll-feed plugin
Now we are going to move to Jekyll-feed plugin, another method.
In the root of the site, please create Gemfile
and add the jekyll-feed
and jekyll
gem:
source 'https://rubygems.org'
gem 'jekyll'
group :jekyll_plugins do
gem 'jekyll-feed'
end
Then, we are able to use a Liquid tag from the plugin instead of adding a <link>
to RSS in the layout like the previous section:
...
{% feed_meta %}
...
Finally, install jekyll-feed
and run jekyll with bundle exec
by running bundle install
on the command line:
bundle exec jekyll serve
We will get a feed of out posts when navigating to /feed.xml
on the live site.
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<generator uri="http://jekyllrb.com" version="3.1.2">Jekyll</generator>
<link href="http://bakery-store.example.com/feed.xml" rel="self" type="application/atom+xml" />
<link href="http://bakery-store.example.com/" rel="alternate" type="text/html" />
<updated>2016-05-13T16:22:08+12:00</updated>
<id>http://bakery-store.example.com/</id>
<entry>
<title>Where Did The Cookie Come From</title>
<link href="http://bakery-store.example.com/information/2016/01/02/where-did-the-cookie-come-from.html" rel="alternate" type="text/html" title="Where Did The Cookie Come From" />
<published>2016-01-02T00:00:00+13:00</published>
<updated>2016-01-02T00:00:00+13:00</updated>
<id>http://bakery-store.example.com/information/2016/01/02/where-did-the-cookie-come-from</id>
<content type="html" xml:base="http://bakery-store.example.com/information/2016/01/02/where-did-the-cookie-come-from.html"><p>The chocolate chip cookie was invented by Ruth Graves Wakefield. She owned the Toll House Inn, in Whitman, Massachusetts, a very popular restaurant that featured home cooking in the 1930s. Her cookbook, Toll House Tried and True Recipes, was first published in 1936 by M. Barrows &amp; Company, New York. The 1938 edition of the cookbook was the first to include the recipe “Toll House Chocolate Crunch Cookie” which rapidly became a favorite cookie in American homes.</p>
<p>Source / Read more <a href="https://en.wikipedia.org/wiki/Chocolate_chip_cookie">Wikipedia</a></p>
</content>
<category term="Information" />
<summary>The chocolate chip cookie was invented by Ruth Graves Wakefield. She owned the Toll House Inn, in Whitman, Massachusetts, a very popular restaurant that featured home cooking in the 1930s. Her cookbook, Toll House Tried and True Recipes, was first published in 1936 by M. Barrows &amp; Company, New York. The 1938 edition of the cookbook was the first to include the recipe “Toll House Chocolate Crunch Cookie” which rapidly became a favorite cookie in American homes.</summary>
</entry>
<entry>
<title>What Is Sour Dough</title>
<link href="http://bakery-store.example.com/information/2016/01/01/what-is-sour-dough.html" rel="alternate" type="text/html" title="What Is Sour Dough" />
<published>2016-01-01T00:00:00+13:00</published>
<updated>2016-01-01T00:00:00+13:00</updated>
<id>http://bakery-store.example.com/information/2016/01/01/what-is-sour-dough</id>
<content type="html" xml:base="http://bakery-store.example.com/information/2016/01/01/what-is-sour-dough.html"><p>Sourdough bread is made by the fermentation of dough using naturally-occurring lactobacilli and yeast. Sourdough bread has a mildly sour taste not present in most breads made with baker’s yeast and better inherent keeping qualities than other breads, due to the lactic acid produced by the lactobacilli.</p>
<p>Source / Read more <a href="https://en.wikipedia.org/wiki/Sourdough">Wikipedia</a></p>
</content>
<category term="Information" />
<summary>Sourdough bread is made by the fermentation of dough using naturally-occurring lactobacilli and yeast. Sourdough bread has a mildly sour taste not present in most breads made with baker’s yeast and better inherent keeping qualities than other breads, due to the lactic acid produced by the lactobacilli.</summary>
</entry>
</feed>
All the fields can be customized at any time. Also, you are allowed to add extra metadata like the author.
Conclusion
Adding an RSS feed to your Jekyll site is a simple yet powerful way to enhance your blog’s reach and keep your audience engaged. Whether you choose the streamlined approach of the jekyll-feed
plugin or delve into the intricacies of crafting a custom feed with Liquid, you’re taking a crucial step towards building a loyal and informed readership.
For more information, please check out more of our related posts to get what you are looking for.