Adding JSON Feed to your Jekyll site

Updated on

Yesterday, Manton Reece and Brent Simmons announced JSON Feed and shared the spec for JSON Feed Version 1.

If you’d like to add support for this feed format to your Jekyll site, create a file at the top-level of your site named feed.json and use the following template:

---
layout: null
---
{
    "version": "https://jsonfeed.org/version/1",
    "title": "{{ site.title | xml_escape }}",
    "description": {{ site.description | jsonify }},
    "home_page_url": "{{ "/" | absolute_url }}",
    "feed_url": "{{ "/feed.json" | absolute_url }}",
    "user_comment": "This feed allows you to read the posts from this site in any feed reader that supports the JSON Feed format.",
    "items": [{% for post in site.posts limit:10 %}
        {
            "id": "{{ post.url | absolute_url }}",
            "url": "{{ post.url | absolute_url }}",
            "title": {{ post.title | jsonify }},
            "content_html": {{ post.content | jsonify }},
            "date_published": "{{ post.date | date_to_xmlschema }}"
        }{% unless forloop.last %},{% endunless %}{% endfor %}
    ]
}

For discovery, you should include a <link> tag that specifies the location of your JSON Feed. Include this tag inside the <head> on your site pages:

<link rel="alternate" type="application/json" title="{{ site.title }}" href="{{ "/feed.json" | absolute_url }}">