# hexo-info-api

JSON endpoints for Hexo posts, categories, and tags, ready for other frontend features

Source: https://works.im0o.top/en/projects/0e405eff/
Date: 2022-09-06
Status: archived
Tags: Developer tools, JavaScript, Hexo, npm

## Project links

- [Source](https://github.com/jz0ojiang/hexo-info-api)
- [Development notes](https://blog.im0o.top/posts/d3bc8dff.html)


hexo-info-api is a Hexo plugin I wrote to export blog data as JSON. Hexo still generates the static website, while another page or tool can read posts, categories, and tags without extracting them from HTML.

## Available data

The built-in modules cover site information, post count, post lists, categories, tags, the latest post, and the latest five posts. Posts can also be selected by category, tag, ID, or path.

List entries include the title, date, description, categories, tags, and original link. Single-post output adds the body. The description uses the post's description field when present and otherwise falls back to excerpt.

A post-count response looks like this:

~~~json
{
  "type": "getPostCount",
  "data": {
    "count": 0
  }
}
~~~

## Selecting modules

After installation, the enabled outputs are selected in Hexo's _config.yml:

~~~yaml
hexo_info_api:
  allowOrigin: "*"
  enable:
    - getInfo
    - getPostCount
    - getPosts
    - getCategories
    - getTags
    - getLatestPost
  disable_default_api: false
~~~

The default /api/ entry lists the enabled endpoints. disable_default_api turns that entry off. Each endpoint has a module under lib/api, and only selected modules are loaded.

![Configuration selects the data modules to generate](https://image.im0o.top/2026/20261117104219833.webp "Configuration selects the data modules to generate")

## Generation and local serving

The implementation uses Hexo generators. A module reads Hexo's content and returns output paths and JSON strings for the site build. Queries by post path are generated as paths for the posts available at build time.

For Hexo Server, a server_middleware filter sets the JSON content type and CORS header under /api/, using allowOrigin from the configuration. Static data generation and local-server headers are handled separately.

I published the plugin on npm, documented the response structures in the repository wiki, and wrote about its development.

[npm](https://www.npmjs.com/package/hexo-info-api) · [Source and API documentation](https://github.com/jz0ojiang/hexo-info-api) · [Development notes](https://blog.im0o.top/posts/d3bc8dff.html)

![The same article records produce static pages and JSON files at build time](https://image.im0o.top/2026/20261117104225251.webp "The same article records produce static pages and JSON files at build time")

