Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
JSON Feed template for Movable Type
{
"version": "https://jsonfeed.org/version/1",
"title": "<$mt:BlogName smarty_pants="1" remove_html="1" escape_for_json="1"$>",
"home_page_url": "<$mt:BlogURL$>",
"feed_url": "<$mt:BlogURL$>feed.json",
"description": "<$mt:BlogDescription smarty_pants="1" remove_html="1" escape_for_json="1"$>",
"favicon": "<$mt:BlogURL$>favicon.ico",
"items": [
<mt:Entries lastn="5">
{
"id": "<$mt:EntryPermalink$>",
"url": "<$mt:EntryPermalink$>",
"title": "<$mt:EntryTitle smarty_pants="1" remove_html="1" escape_for_json="1"$>",
"content_html": "<$mt:EntryBody escape_for_json="1"$>",
"summary": "<$mt:EntryExcerpt escape_for_json="1"$>",
"date_published": "<$mt:EntryDate utc="1" format_name="iso8601"$>",
"date_modified": "<$mt:EntryModifiedDate utc="1" format_name="iso8601"$>",
"author": {
"name": "<$mt:EntryAuthorDisplayName escape_for_json="1"$>"
}
}<mt:Unless name="__last__">,</mt:Unless>
</mt:Entries>
]
}
@defjaf

This comment has been minimized.

Copy link

defjaf commented Jan 31, 2019

I note that your template doesn't have an entry for tags (aka categories). I think the following works:

      <mt:if tag="EntryCategory">"tags": [<mt:EntryCategories glue=", ">"<$mt:CategoryLabel escape_for_json="1"$>"</mt:EntryCategories><mt:if tag="Tags">, <mt:EntryTags glue=", ">"<$mt:TagName escape_for_json="1"$>"</mt:EntryTags></mt:if>],
      <mt:ElseIf tag="Tags">"tags": [<mt:EntryTags glue=", ">"<$mt:TagName escape_for_json="1"$>"</mt:EntryTags>],</mt:if>

JSONfeed doesn't distinguish between tags and categories, so I've combined them. However, because of (I think) the lack of boolean "or", I split this into two parts, one of there are Categories and possibly tags, and another if there are only tags.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.