What this will do is generate a two different feeds:
- A
feed.xml
for your local development, which will contain the values you specify for yourdevelopment
environment in your_config.yml
. - A
feed.xml
for your live site, which will have the values set in your_config.yml
for yourproduction
environment.
This is necessary because without different values for title, description, etc, many feed readers will view the two feeds as the same, even if the post content is different This makes it difficult to test if your feed is working and updating locally.
You could add additional environments as well, such as development
, test
, staging
, and production
.
Here's what your feed.xml
should look like:
---
layout: none
---
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
{% assign feed = site.feed[jekyll.environment] %}
<channel>
<title>{{ feed.title | xml_escape }}</title>
<description>{{ feed.description | xml_escape }}</description>
<link>{{ feed.url }}</link>
<atom:link href="{{ feed.url }}/feed.xml" rel="self" type="application/rss+xml" />
{% for post in site.posts limit: feed.items %}
<item>
<title>{{ post.title | xml_escape }}</title>
<description>{{ post.description | xml_escape }}</description>
<pubDate>{{ post.date | date: "%a, %d %b %Y %H:%M:%S %z" }}</pubDate>
<link>{{ feed.url }}{{ post.url }}</link>
<guid isPermaLink="true">{{ feed.url }}{{ post.url }}</guid>
</item>
{% endfor %}
</channel>
</rss>
And here's what your _config.yml
file should look like:
title: An Awesome Blog
description: My blog, which is awesome
url: https://an-awesome-blog.com
feed:
production:
title: An Awesome Blog
description: My blog, which is awesome
url: https://an-awesome-blog.com
items: 10
development:
title: LOCAL An Awesome Blog
description: LOCAL blog, which is still awesome
url: http://127.0.0.1:4000
items: 5