Official blog of Daniel Uhlmann

Customize your RSS Feed in a Ghost Theme

A few days ago, I wanted to adjust my RSS feed for this blog. I wasn’t entirely happy with my previous feed layout, so I wanted to make some changes. One of these changes was, for example, using excerpts, which Ghost offers, to write a kind of summary of the posts I write.

Add a custom route

As preliminary work, we must first add a custom route in the settings of our Ghost instance, which reflects the URL under which our RSS feed should then be accessible. To do this, we navigate to Admin settings -> Labs and download routes.yaml for editing.

Under routes add the URL where your new custom rss feed will exist and reupload the file. In my case, I configured the following:

1routes:
2/rss/:
3template: rss
4content_type: text/xml

Custom rss feeds need to be defined with the content_type property.

Create a new template

To customize our RSS feed we need to create a new template on the root level of our currently used Ghost theme. I am presently using the atilla theme so my path looked like this:

themes/attila-3.8.1/rss.hbs

So create a new file called rss.hbs and save it under the above-mentioned path.

You can use the following template if you want an RSS feed that looks like the one on this blog:

 1<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/" version="2.0">
 2<channel>
 3<title><![CDATA[ {{@site.title}} ]]></title>
 4<description><![CDATA[ {{@site.description}} ]]></description>
 5<link>{{@site.url}}</link>
 6<image>
 7    <url>{{@site.url}}/favicon.png</url>
 8    <title>{{@site.title}}</title>
 9    <link>{{@site.url}}</link>
10</image>
11<lastBuildDate>{{date format="ddd, DD MMM YYYY HH:mm:ss ZZ"}}</lastBuildDate>
12<atom:link href="{{@site.url}}" rel="self" type="application/rss+xml"/>
13<ttl>60</ttl>
14
15{{#get "posts" limit="all" include="authors,tags"}}
16    {{#foreach posts}}
17    <item>
18        <title><![CDATA[ {{title}} ]]></title>
19        <description><![CDATA[
20            {{excerpt}}
21            <br/><br/>
22            Read the full article here: <a href="{{url absolute="true"}}">{{title}}</a>
23        ]]></description>
24        <link>{{url absolute="true"}}</link>
25        <guid isPermaLink="false">{{id}}</guid>
26        <dc:creator><![CDATA[ {{primary_author.name}} ]]></dc:creator>
27        <pubDate>{{date format="ddd, DD MMM YYYY HH:mm:ss ZZ"}}</pubDate>
28    </item>
29    {{/foreach}}
30{{/get}}
31
32</channel>
33</rss>

This template uses pre-defined variables that Ghost has to offer.

The result of a blog post that is displayed in an RSS reader will look something similar to this:

Ghost blog post

Once you have completed these steps, you can also use the excerpts provided by Ghost. For example, you can use the template I have shown you to write a summary of your blog post. Readers who are then interested in the whole article can read the entire post on your blog.

<< Previous Post

|

Next Post >>