Working on updating my site and converting what I had worked on for an XML RSS feed into a more current JSON feed within a Kirby CMS controller file. https://github.com/getkirby
my redesigned site will launch soon in 2024 and will feature the JSON formatted feed. https://lukedorny.com
Since you're here you should browse the available elements in the jsonfeed.org made by Manton Reese and Brent Simmons. Maybe there are a few elements you could add to this that I haven't. It looks much more flexible than the XML feed format.
Remember, we are now serving application/feed+json
and the JSON feed format is 'version' => 'https://jsonfeed.org/version/1.1'
, also, the URL for the feed link in your header should use this PHP code:
<link rel="alternate" type="application/feed+json"
title="<?= $site->title()->esc() ?>"
href="<?= $site->rssfeed()->toPage()->url() ?>" />
Of course, if you'd just like to link to your feed page directly, bypassing my silly panel page chooser for the feed, your header should use this more normal PHP code:
<link rel="alternate" type="application/feed+json"
title="<?= $site->title()->esc() ?>"
href="<?= page('feed')->url() ?>" />
I created a few files to make this work:
/site/templates/feed.json.php
/site/blueprints/feed.json.yml
/site/controllers/feed.json.php
/content/feed/feed.json.txt
- /site/config/config.php
This setup assumes several content folders of pages to round up for the Feed.
- In my case, I added a
Pages
field in the/site/blueprints/site.yml
file to choose what page in my site would be the RSS feed. This might seem extra, but it works for my needs. - Then in the second file above (
/site/blueprints/feed.json.yml
), I added aPages
field so I could select which content parents that have children I wanted to include in my feed. For example, I added/content/articles/
,/content/updates/
,/content/nowplaying/
so that each of their children will get into the feed. - Let's sort the combined pages by date.
- Next I added two additional textarea fields
rssblip
in that blueprint for the description of the feed, as well as the text I'd like to add at the end of each Feed item, encouraging readers to get in touch or reply via email, engage on Mastodon, what have you (alternatively you could just pipe in the SEO description of your site to the top of the feed as well if you like). - Then we move on to the template. The template is rather short, as you'll see. Unfortunately, creating the feed will end up being in the Controller mostly.
- Next the controller file. This grabs the sections we want to include, sorts them, and grabs post images that use the typical Kirby
cover
image method but falls back to the first image available in each post. - Then the controller creates the $items array for the feed. This is an array of all of your site pages that will be included.
- Then it takes the
cover
image and wraps it in afigure
, addsalt
text, afigcaption
that allows links using the->kirbytext()
powers, etc. - In the new
$content_html
object it first adds in the page's text content and strips out extra new lines of code. - Then it adds the
cover
to the beginning of that new$content_html
. - You can add in other field data you may have for your pages, here I have added
$materials
at the end, for a project I'm doing that I'll soon launch on the site. - It also adds in the
rssblip
at the end, which has four----
in the textarea to give it a divider from the item's content below it - I added the title of each item's parent to differentiate it from other posts, too (i.e.: "Articles: ", "Updates: ", etc.)
- Then it assembles the
$items
using the various objects we've created as well as fields from each page. - Returns the
$items
for use. - You'll see all of the data come together in the template.
If you have suggestions to make this better please fork it, change it, whatever you like. Cheers!

— Luke
This was built and working within a Kirby v4.+ install.