Hexo (https://hexo.io/) plugin to generate a JSON file as site feed with posts contents for generic use or consumption.
It's useful to serve compact and agile content data for microservices like AJAX site search, Twitter typeahead or public API.
JSON output can be similar to RSS like structure (default) or the new JSON Feed spec.
It is now possible to:
- Select one of two specs to build your JSON: RSS like or JSON Feed
The output file name now will be rss.json or feed.json, depends on your spec setting. See bellow.
npm i -S hexo-generator-json-feedHexo will run the generator automagically when you run hexo serve or hexo generate.
:smirk:
The output JSON file will depend on you spec setting. Options are rss (default) or feed. This option defines the data structure and the name of the JSON file output.
Using the default settings (RSS), the rss.json file will look like the following structure:
{
title: hexo.config.title,
description: hexo.config.description,
language: hexo.config.language,
link: hexo.config.url,
webMaster: hexo.config.author,
pubDate: post.date, // Last published post pubdate, UTC format, RSS pattern
lastBuildDate: new Date(), // JSON file build datetime, UTC format, RSS pattern
generator: 'hexo-generator-json-feed',
items: [
{
title: post.title,
link: post.permalink,
description: post.excerpt ? post.excerpt : post.content, // only text minified ;)
pubDate: post.date, // UTC format, RSS pattern
guid: post.permalink,
category: post.categories.length ? post.categories : post.tags // Strings Array
}
]
}If you set spec as feed in your _config.yml, like this:
jsonFeed:
spec: feedThen, your file will be a feed.json looking like the following structure:
{
version: 'https://jsonfeed.org/version/1',
title: hexo.config.title,
home_page_url: hexo.config.url,
feed_url: `${hexo.config.url}/feed.json`,
author: {
name: hexo.config.author
},
items: [
{
id: post.permalink,
url: post.permalink,
title: post.title,
content_html: post.content,
content_text: post.content, // only text minified ;)
summary: post.excerpt || post.content, // only text minified ;)
date_published: post.date, // JSON universal date RFC 3339 format
tags: [...categories.names, ...tags.names]
}
]
}You can customize settings in _config.yml.
Default settings are:
jsonFeed:
spec: rss
limit: 25hexo.util.stripHTML is used to get only clean text for post excerpt or content.