Skip to content

Instantly share code, notes, and snippets.

@aprescott
Last active December 14, 2015 17:49
Show Gist options
  • Save aprescott/5124837 to your computer and use it in GitHub Desktop.
Save aprescott/5124837 to your computer and use it in GitHub Desktop.
Sample feed.xml Liquid template for use with Serif 0.3.2. Post unique IDs are independent of URL. Note the caveats!
layout: none
<?xml version="1.0" encoding="utf-8"?>
{% assign feed_url = "http://example.com/feed" %}
{% assign feed_title = "Example Feed" %}
{% assign feed_alternate = "http://example.com/blog" %}
{% assign feed_global_unique_id = "tag:example.com,2013:TOTALLY-RANDOM-STRING-OF-CHARACTERS-GOES-HERE" %}
{% assign feed_author_name = "J. Smith" %}
{% assign feed_author_url = "http://example.com/about" %}
{% assign feed_entry_tag_domain = "example.com" %}
<feed xmlns="http://www.w3.org/2005/Atom">
<title>{{ feed_title }}</title>
<link rel="self" type="application/atom+xml" href="{{ feed_url }}"/>
<link rel="alternate" type="text/html" href="{{ feed_alternate }}"/>
<id>{{ feed_global_unique_id }}</id>
<updated>{{ site.latest_update_time | xmlschema }}</updated>
<author>
<name>{{ feed_author_name }}</name>
<uri>{{ feed_author_url }}</uri>
</author>
{% for post in site.posts limit:10 %}
<entry>
<id>tag:{{ feed_entry_tag_domain }},{{ post.created | date: "%Y-%m-%d" }}:{{ post.created | date: "%s" }}</id>
<title type="html">{{ post.title | smarty | replace:"&","&amp;" | replace:"<","&lt;" | replace:">","&gt;" }}</title>
<updated>{{ post.updated | xmlschema }}</updated>
<published>{{ post.created | xmlschema }}</published>
<link href="{{ post.url }}" rel="alternate" type="text/html"/>
<content type="html">{{ post.content | markdown | escape }}</content>
</entry>
{% endfor %}
</feed>

To use

  1. Change feed_url to where the feed will be served from.
  2. Change feed_title to wahtever your feed's title should show up as in feed readers.
  3. Set feed_alternate to the URL where the content can be seen as regular HTML.
  4. feed_global_unique_id uses the tag: URI here, and should:
    1. have example.com changed to your blog domain,
    2. have 2013 changed to whatever year is appropriate for the feed starting,
    3. use a globally unique string of characters after the second :,
    4. most importantly, never ever change, even if the feed moves to a different domain or URL, or anything else --- change the ID and readers will assume entirely different content → posts will suddenly become duplicated in the likes of Google Reader.
  5. Set your author name and a URL. In this template, it's used for all entries since each entry doesn't have its own author.
  6. Change the feed_entry_tag_domain to be a domain name that should never change. This is used in tag: URIs for the entry ID. If this changes, the entry ID changes, and feed readers will see different content → posts will suddenly become duplicated in the likes of Google Reader. If you want to change ID scheme, make sure to keep the ID the same on older posts, using a conditional.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment