Giter Site home page Giter Site logo

hexo-generator-restful's Introduction

hexo-generator-restful

Generate restful json data for Hexo plugins.

生成 restful 风格的 json 数据,可以当作 api 接口,开始构建一个 SPA 应用吧。

Install

npm install hexo-generator-restful --save

Config

以下为默认配置,属性值为 false 表示不生成。

restful:
  # site 可配置为数组选择性生成某些属性
  # site: ['title', 'subtitle', 'description', 'author', 'since', email', 'favicon', 'avatar']
  site: true        # hexo.config mix theme.config
  posts_size: 10    # 文章列表分页,0 表示不分页
  posts_props:      # 文章列表项的需要生成的属性
    title: true
    slug: true
    date: true
    updated: true
    comments: true
    path: true
    excerpt: false
    cover: true      # 封面图,取文章第一张图片
    content: false
    keywords: false
    categories: true
    tags: true
  categories: true         # 分类数据
  use_category_slug: false # Use slug for filename of category data
  tags: true               # 标签数据
  use_tag_slug: false      # Use slug for filename of tag data
  post: true               # 文章数据
  pages: false             # 额外的 Hexo 页面数据, 如 About

Document

Get Hexo Config

获取所有 Hexo 配置(站点配置和主题配置)。

Request
GET /api/site.json
Response

/api/site.json

Get Posts

如果配置 posts_size: 0 则不分页,以下请求会获取全部文章。

Request
GET /api/posts.json
Response

示例为分页配置下的数据,会包含分页属性 totalpageSizepageCount,不分页的数据不包含这三项。

/api/posts.json

Get Posts By Page

获取分页数据

Request
GET /api/posts/:PageNum.json
Response

/api/posts/1.json

Get All Tags

获取所有文章标签,如果文章无标签则不生成。

Request
GET /api/tags.json
Response

/api/tags.json

Get Posts By Tag

获取某一标签下的所有文章

Request
GET /api/tags/:TagName.json
Response

/api/tags/Hexo.json

Get All Categories

获取所有文章分类,如果文章无分类则不生成。

Request
GET /api/categories.json
Response

数据格式同 Get All Tags

Get Posts By Categorie

获取某一分类下的所有文章

Request
GET /api/categories/:CategorieName.json
Response

数据格式同 Get Posts By Tag

Get Post By Slug

根据文章别名获取文章详细信息

Request
GET /api/articles/:Slug.json
Response

/api/articles/javascript-advanced-functions.json

Get Implecit Pages

获取来自主题的 Hexo 隐式页面内容,如 About 等。因隐式页面(除 About 等导航栏入口页外)一般在 Hexo 不提供直接访问入口,调用此 API 的开发者需要了解其完整路径,此接口默认关闭。

例如:

Request
GET /api/pages/about.json
Response

格式类似于于 Get Post By Slug。

hexo-generator-restful's People

Contributors

changkun avatar fzits avatar kennx avatar rangeryu avatar siamak avatar yscoder avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

hexo-generator-restful's Issues

返回的属性冲突

比如作者返回的属性中有一个为cover,而在我的主题配置中有一个cover属性代表另一种意思(是否显示封面图),当我设置cover: true的时候,返回的cover属性会变成我设置的值而不会取文章的第一张图片

How about add permalink to posts list?

I using hexo-generator-restful plugin to get latest posts of my blog in other site.
And I want to show post list with link, but there are no field about permalink.
So, I need to create a permalink on a site other than my blog. Yes, it's not cool.

I think it would be more useful to add a permalink field to the post list API.

关于文章目录的返回

这个插件十分好用,但是在使用过程中我遇到了一个问题:markdown中我设置了文章自身的目录(toc),且在hexo生成的网页中也显示了文章的目录,但是似乎在通过api获取的文章数据中并不包含目录信息。请问可以支持返回文章的目录吗?

Not working for me

How do you get this to work?

I installed it with NPM.
Copied the yml restful config into my hexo _config.yml
Then did hexo serve.

When I visit localhost:4000/api/posts.json or site.json nothing comes up.

I also tried running hexo generate.

What am I missing?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.