Adding a JSON feed for blog posts
As well as RSS, you can now read and subscribe to my blog via a new JSON feed - based on the JSON Feed specification.
It was very easy to add to my website by creating this file at source/blog.json.twig:
---
permalink: /blog.json
use: [posts]
---
{
"version": "https://jsonfeed.org/version/1.1",
"title": "Blog | {{ site.name }} - {{ site.slogan }}",
"icon": "{{ site.url }}/assets/images/social-avatar-blue.jpg",
"home_page_url": "https://www.jsonfeed.org",
"feed_url": "{{ site.url }}/blog.json",
"items": [
{% for post in data.posts %}
{
"id": "{{ site.url }}{{ post.url }}",
"title": "{{ post.title }}",
"content_html": {{ post.blocks.content|json_encode|raw }},
"date_published": "{{ post.date|date("c") }}",
"url": "{{ site.url }}{{ post.url }}"
}{% if not loop.last %},{% endif %}
{% endfor %}
]
}
It was also easy to configure Caddy to return the appropriate application/feed+json content type:
@blogfeed {
path /blog.json
}
header @blogfeed Content-Type application/feed+json
I'm a big proponent of the Open Web and people owning their content, so I want to make it as easy as possible for everyone to find and consume my posts, and will probably add more JSON feeds for my presentation content and book updates in the future.
I may also create it as a standalone Sculpin plugin, as it's not specific to my website and would allow others to share their content in the same way.