Ghost comes with automatic RSS feeds for your content, but you can also create a custom feed using the flexible dynamic routing layer to support specific content types, like videos and podcasts.

Adding /rss/ to most URLs in Ghost produces an automatically generated RSS feed for your content. If you're publishing a podcast on your Ghost site then you'll probably want to create a custom RSS feed to distribute your podcast episodes to places like iTunes.

This tutorial walks you through how to create a custom RSS route using dynamic routing, as well as a Handlebars template for your RSS feed that is fully optimised for a podcast and iTunes.

Add a new route for your RSS feed

The first thing to do is add a new route where your RSS feed will exist in the using the dynamic routing layer in Ghost. Download the most up to date version of your routes.yaml file from Ghost Admin settings menu and open it in your code editor of choice.

For the purposes of this example, we're adding this to our podcast collection - here's what it looks like:

routes:
  /podcast/rss/:
    template: podcast/rss
    content_type: rss

Note that this assumes we already have a collection in place for the podcast content, which would appear under collections in the routes.yaml file like so:

collections:
  /blog/:
    permalink: /blog/{slug}/
    filter: tag:blog
  /podcast/:
    permalink: /podcast/{slug}/
    filter: tag:podcast

If you haven't yet setup your podcast content in Ghost, then you can use this tutorial on content collections as a guide.

Create a new template for an iTunes RSS feed

Now you've updated the routes.yaml, you'll need to create a new Handlebars template in your theme. This requires a little bit of coding, but you can use the example provided in this tutorial as a starting point.


Define your podcast channel for iTunes

In order for iTunes to understand your RSS feed, there a few basic requirements that you need to include at the start of your new template, which defines the type of RSS feed and some basic information about your podcast. Below is an example of the required information for an iTunes podcast, which you can copy into your own template and replace with necessary information:

<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"
    xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
    xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd"
    xmlns:rawvoice="http://www.rawvoice.com/rawvoiceRssModule/" xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0">

<channel>
<title>{{@blog.title}}</title>
<link>{{@blog.url}}</link>
<description>{{@blog.description}}</description>
<language>{{lang}}</language>
<copyright>{{@blog.title}} Copyright {{date format="YYYY"}}</copyright>
<atom:link href="{{@blog.url}}/podcast/rss/" rel="self" type="application/rss+xml" />
<lastBuildDate>{{date format="ddd, DD MMM YYYY HH:mm:ss ZZ"}}</lastBuildDate>
<itunes:author>{{@blog.title}}</itunes:author>
<itunes:summary>{{@blog.description}}</itunes:summary>
<itunes:owner>
    <itunes:name>Your Name</itunes:name>
    <itunes:email>youremail@example.com</itunes:email>
</itunes:owner>
<itunes:explicit>clean</itunes:explicit>
<itunes:image href="{{img_url @blog.icon absolute="true"}}"/>
<itunes:category text="Technology"></itunes:category>

{{#get "posts" filter="tag:podcast" include="tags,authors" as |episode|}}
    {{#foreach episode}}
    <item>
        <title>{{title}}</title>
        <link>{{url absolute="true"}}</link>
        <pubDate>{{date format="ddd, DD MMM YYYY HH:mm:ss ZZ"}}</pubDate>
        <guid isPermaLink="false">{{id}}</guid>
        <category><![CDATA[ {{primary_tag}} ]]></category>
        <description>{{custom_excerpt}}</description>
        <content:encoded><![CDATA[ {{content}} ]]></content:encoded>
        <enclosure url="{{og_description}}" length="0" type="audio/mpeg"/>
        <itunes:subtitle>{{custom_excerpt}}</itunes:subtitle>
        <itunes:summary><![CDATA[ {{content}} ]]></itunes:summary>
    </item>
    {{/foreach}}
{{/get}}

</channel>
</rss>

You can copy and paste this exact implementation for your site, then go ahead and customise it to suit your needs! There are a couple of static variables which need to be adjusted, like your name, email, and the iTunes category you want to appear in.

There's also one very small hack/workaround that makes all of this work: The feed requires that you specify the podcast mp3/audio file URL for each episode. Because Ghost doesn't have custom fields, we can repurpose the Facebook Description field for each post to store the link to the audio file.

So wherever you upload your audio to, just paste the provided URL into the Facebook Description and you should be all set.

Update routes.yaml and your active theme

Once you're happy with your work, upload a new version of routes.yaml and update your active theme in Ghost Admin to enable your new RSS feed. Once you have done this, you should be able to visit the feed at /podcast/rss/ to ensure it's working as desired and submit it to iTunes.

Summary

Success! You should have implemented your very own custom iTunes RSS feed for podcast content on your Ghost site using dynamic routing and a Handlebars template. Don't forget you can get more in-depth information about the Handlebars theme layer in Ghost in the docs.