Giter Club home page Giter Club logo

hexo-generator-api's Introduction

hexo-generator-api

npm version Build Status Coverage Status Dependency Status

Generate json api for your awesome hexo site

Installation

$ npm install hexo-generator-api --save

API Generation

List

A list of posts of the blog. Generated in public/api/list. Lists are by default paginated. You can set the number of posts in a page via setting api_posts_per_page.

The first list page will be generated to public/api/list/list.json, the following pages will be generated to public/api/list/list-${pageNumber}.json.

An example list page will be

{
    "prev": "http://yoursite.com/api/list/list.json",   // previous list page (null if not exists)
    "next": "http://yoursite.com/api/list/list-3.json", // next list page (null if not exists)
    "posts": [{
        "title": "test",
        "permalink": "http://yoursite.com/2014/11/14/test/",
        "date": 1415928246000,
        "url": "http://yoursite.com/api/posts/51lslnjeqrtdxf3k.json"
    }, {
        "title": "test",
        "permalink": "http://yoursite.com/2014/11/14/test-3/",
        "date": 1415929901000,
        "url": "http://yoursite.com/api/posts/7qdz6o08kjizb7zs.json"
    }, {
        "title": "test",
        "permalink": "http://yoursite.com/2014/11/14/test-4/",
        "date": 1415929902000,
        "url": "http://yoursite.com/api/posts/3hevgb4ty7txp68c.json"
    }, {
        "title": "test",
        "permalink": "http://yoursite.com/2014/11/14/test-5/",
        "date": 1415929903000,
        "url": "http://yoursite.com/api/posts/1jmthulquk4e9sum.json"
    }, {
        "title": "test",
        "permalink": "http://yoursite.com/2014/11/14/test-6/",
        "date": 1415929904000,
        "url": "http://yoursite.com/api/posts/e20vj4gx5pcd14s3.json"
    }]
}
Recent

A list of the most recent posts of the blog. Generated in public/api/list. The number of recent posts is defined by default paginated. You can set the number of posts via the api_posts_per_page setting.

The api end point will be to public/api/list/recent.json.

An example list page will be the same as above, but in the reverse order they were published newest to oldest

{
    "posts": [{
        "title": "test",
        "permalink": "http://yoursite.com/2014/11/14/test/",
        "date": 1415929904000,
        "url": "http://yoursite.com/api/posts/51lslnjeqrtdxf3k.json"
    }, {
        "title": "test",
        "permalink": "http://yoursite.com/2014/11/14/test-3/",
        "date": 1415929903000,
        "url": "http://yoursite.com/api/posts/7qdz6o08kjizb7zs.json"
    }, {
        "title": "test",
        "permalink": "http://yoursite.com/2014/11/14/test-4/",
        "date": 1415929902000,
        "url": "http://yoursite.com/api/posts/3hevgb4ty7txp68c.json"
    }, {
        "title": "test",
        "permalink": "http://yoursite.com/2014/11/14/test-5/",
        "date": 1415929901000,
        "url": "http://yoursite.com/api/posts/1jmthulquk4e9sum.json"
    }, {
        "title": "test",
        "permalink": "http://yoursite.com/2014/11/14/test-6/",
        "date": 1415928246000,
        "url": "http://yoursite.com/api/posts/e20vj4gx5pcd14s3.json"
    }]
}
Post

Every post will have a single JSON file to hold the result located in public/api/posts.

An example post will be

{
    "title": "test",
    "permalink": "http://yoursite.com/2014/11/14/test-4/",
    "date": 1415929902000,
    "raw": "title: test\ndate: 2014-11-14 09:51:42\ntags:\n---\n This is a very good post."
}

For real world example, here are some of them:

Options

Set options in _config.yml.

# Posts displayed per page in list
api_posts_per_page: 5

Contribute

Your contributions will be welcomed! Just :

  • fork
  • submit issue
  • propose pull request

LICENSE

MIT

hexo-generator-api's People

Contributors

adrieankhisbe avatar nxfifteen avatar tjwudi 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

Watchers

 avatar  avatar  avatar  avatar

hexo-generator-api's Issues

happened an error

FATAL Something's wrong. Maybe you can find the solution here: http://hexo.io/docs/troubleshooting.html
TypeError: callback is not a function
    at Hexo.<anonymous> (/Users/duanxudong/Documents/blog/node_modules/hexo-generator-api/index.js:102:3)
    at Hexo.tryCatcher (/Users/duanxudong/Documents/blog/node_modules/hexo/node_modules/bluebird/js/main/util.js:26:23)
    at Hexo.ret (eval at <anonymous> (/Users/duanxudong/Documents/blog/node_modules/hexo/node_modules/bluebird/js/main/promisify.js:163:12), <anonymous>:14:23)
    at Hexo.tryCatcher (/Users/duanxudong/Documents/blog/node_modules/hexo/node_modules/bluebird/js/main/util.js:26:23)
    at Hexo.<anonymous> (/Users/duanxudong/Documents/blog/node_modules/hexo/node_modules/bluebird/js/main/method.js:15:34)
    at /Users/duanxudong/Documents/blog/node_modules/hexo/lib/hexo/index.js:325:24
    at tryCatcher (/Users/duanxudong/Documents/blog/node_modules/hexo/node_modules/bluebird/js/main/util.js:26:23)
    at MappingPromiseArray._promiseFulfilled (/Users/duanxudong/Documents/blog/node_modules/hexo/node_modules/bluebird/js/main/map.js:56:38)
    at MappingPromiseArray.init (/Users/duanxudong/Documents/blog/node_modules/hexo/node_modules/bluebird/js/main/promise_array.js:92:18)
    at MappingPromiseArray.init (/Users/duanxudong/Documents/blog/node_modules/hexo/node_modules/bluebird/js/main/map.js:29:23)
    at Async._drainQueue (/Users/duanxudong/Documents/blog/node_modules/hexo/node_modules/bluebird/js/main/async.js:128:12)
    at Async._drainQueues (/Users/duanxudong/Documents/blog/node_modules/hexo/node_modules/bluebird/js/main/async.js:133:10)
    at Immediate.Async.drainQueues [as _onImmediate] (/Users/duanxudong/Documents/blog/node_modules/hexo/node_modules/bluebird/js/main/async.js:15:14)
    at processImmediate [as _immediateCallback] (timers.js:383:17)
FATAL TypeError: callback is not a function
    at Hexo.<anonymous> (/Users/duanxudong/Documents/blog/node_modules/hexo-generator-api/index.js:102:3)
    at Hexo.tryCatcher (/Users/duanxudong/Documents/blog/node_modules/hexo/node_modules/bluebird/js/main/util.js:26:23)
    at Hexo.ret (eval at <anonymous> (/Users/duanxudong/Documents/blog/node_modules/hexo/node_modules/bluebird/js/main/promisify.js:163:12), <anonymous>:14:23)
    at Hexo.tryCatcher (/Users/duanxudong/Documents/blog/node_modules/hexo/node_modules/bluebird/js/main/util.js:26:23)
    at Hexo.<anonymous> (/Users/duanxudong/Documents/blog/node_modules/hexo/node_modules/bluebird/js/main/method.js:15:34)
    at /Users/duanxudong/Documents/blog/node_modules/hexo/lib/hexo/index.js:325:24
    at tryCatcher (/Users/duanxudong/Documents/blog/node_modules/hexo/node_modules/bluebird/js/main/util.js:26:23)
    at MappingPromiseArray._promiseFulfilled (/Users/duanxudong/Documents/blog/node_modules/hexo/node_modules/bluebird/js/main/map.js:56:38)
    at MappingPromiseArray.init (/Users/duanxudong/Documents/blog/node_modules/hexo/node_modules/bluebird/js/main/promise_array.js:92:18)
    at MappingPromiseArray.init (/Users/duanxudong/Documents/blog/node_modules/hexo/node_modules/bluebird/js/main/map.js:29:23)
    at Async._drainQueue (/Users/duanxudong/Documents/blog/node_modules/hexo/node_modules/bluebird/js/main/async.js:128:12)
    at Async._drainQueues (/Users/duanxudong/Documents/blog/node_modules/hexo/node_modules/bluebird/js/main/async.js:133:10)
    at Immediate.Async.drainQueues [as _onImmediate] (/Users/duanxudong/Documents/blog/node_modules/hexo/node_modules/bluebird/js/main/async.js:15:14)
    at processImmediate [as _immediateCallback] (timers.js:383:17)

Release 0.1.2

Key tasks include:

  • Fix broken example link
  • Push to NPM

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.