Static Site Generation With Grow: How to Set Up Syndication Feeds
Published on NovĀ 13, 2017 (updated MayĀ 18, 2024), filed under development (feed). (Share this on Mastodon orĀ Bluesky?)
This post is possibly outdated.
Grow is a static site generator that Iāve slowly been switching to on my own projectsārecently with (officially still unannounced) HH Kaffee. Iāve been switching to Grow because of its ambitions around quality, its unique internationalization capabilities, my familiarity with the system (weāve used like at Google), and my familiarity with the team (Iāve worked with all of them at Google, and theyāre some of the greatest people Iāve worked with as well). [Later, in 2021, I then switched from Grow to Eleventy.]
Itās been ages that Iāve last written anything like a technical how-to (if you exclude my books) but here, now, I wish to lay out how to do something with Grow thatās not overly difficult, but also not well-documentedāto set up syndication feeds.
1. Set Up a Feed Template
There are differences between RSS and Atom making Atom the more desirable syndication format, however Iām okay with using RSS (2.0) for a feed, and not Atom. You may not find it hard to use Atom instead.
The first step is to create respective view. I suggest to set up a feed.xml like the following:
<?xml version="1.0" encoding="utf-8" ?>
<rss version="2.0">
<channel>
<title>{{podspec.title}}</title>
<link>{{doc.pod.env.url}}</link>
<description>{{podspec.description}}</description>
<language>{{doc.locale}}</language>
{% for items in g.collections(['roasters', 'cafes', 'posts']) %}
{% for item in (items.docs(order_by='date', reverse=True) | list)[0:5] %}
<item>
<title>{{item.title}}</title>
<link>{{item.url}}</link>
<description>{% if item.html %}<![CDATA[
{{item.html|striptags|truncate(250, end=' ā¦')}}
]]>{% endif %}</description>
{%+ if item.date %}<pubDate>{{item.date|date(format='d MMM YYYY', locale='en')}}</pubDate>{% endif %}
<guid>{{item.url}}</guid>
</item>
{% endfor %}
{% endfor %}
</channel>
</rss>
The template is not perfect yet (Iāve only had one scrutinizing look at the RSSĀ 2.0 spec and Iām stillānotice the {%+
āimproving output formatting) but it should work for this demonstration. Iām thinking about putting the project in question up on GitHub I put the project up on GitHub [latest version using Grow: 1.71.0], and plan to use prettier code sample embeds.
The most important thing to note is probably the selection of news items. In this case, the feed pulls from three collections (the roasters, cafƩs, and posts featured on HH Kaffee) to pick five of each in reverse chronological order.
You can leave the collections array blank or should otherwise select your own collections (g.collections(['roasters', 'cafes', 'posts'])
); likewise, then, can you choose a different number of items to be included ([0:5]
).
2. Set Up a Feed View
Next, define the feedās view, which is just a simple frontmatter YAML file (/pages/feed.yaml here):
$path@: /feed/index.xml
$view: /views/feed.xml
$hidden: true
This is also just from my own setup, where $view
is key to link the template and $hidden
is useful not to link the feed in the navigation (I populate the nav through all /pages).
3. Test
Lastly, test your feed fileāwith this and the default Grow setup, it should reside at localhost:8080/feed/index.xml. (To compare with HH Kaffeeās current output, check hhkaffee.com/feed/.)
There are different views on correct feed MIME types but make sure to test your feed to be delivered correctly. Personally I rely on my providersā defaults (which all seem to be application/xml
) and donāt have any problems with those.
ā§ That much for how to add feeds in Grow. As Iām moving away from my old (but accidental) āeither manual or WordPressā approach, specifically in those projects where I want quality and scalability, I may write more about Grow in the future. Keep it locked.
About Me
Iām Jens (long: Jens Oliver Meiert), and Iām a web developer, manager, and author. Iāve been working as a technical lead and engineering manager for companies youāve never heard of and companies you use every day, Iām an occasional contributor to web standards (like HTML, CSS, WCAG), and I write and review books for OāReilly and Frontend Dogma.
I love trying things, not only in web development and engineering management, but also in other areas like philosophy. Here on meiert.com I share some of my experiences and views. (I value you being critical, interpreting charitably, and giving feedback.)