- "+ 35 | ""+ 36 | collections[i].book.title+ 37 | "
- "+ 38 | collections[i].updated+ 39 | "
- "+ 40 | collections[i].comment+ 41 | "
├── .gitignore
├── .npmignore
├── README.md
├── index.js
├── lib
└── generator.js
└── package.json
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules
2 | /
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | .git*
2 | .npmignore
3 | .travis.yml
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # hexo-generator-douban
2 |
3 | Douban page generator plugin for Hexo.
4 |
5 | ## Install
6 |
7 | ``` bash
8 | $ npm install hexo-generator-douban --save
9 | ```
10 |
11 | ## Options
12 |
13 | You can configure this plugin in `_config.yml`.
14 |
15 | ``` yaml
16 | douban:
17 | user: douban_id
18 | ```
19 |
20 | - **user** - Your douban user id.
21 |
22 | ## Demo
23 |
24 | See [demo](http://yikun.github.io/douban/).
--------------------------------------------------------------------------------
/index.js:
--------------------------------------------------------------------------------
1 | var assign = require('object-assign');
2 |
3 | hexo.config.douban = assign({
4 | per_page: hexo.config.per_page,
5 | }, hexo.config.douban);
6 |
7 | hexo.extend.generator.register('douban', require('./lib/generator'));
--------------------------------------------------------------------------------
/lib/generator.js:
--------------------------------------------------------------------------------
1 | var request = require('urllib-sync').request;
2 |
3 | module.exports = function(locals){
4 | var config = this.config;
5 | var contents='';
6 | var start = 0;
7 | var total = 20;
8 | var count = 20;
9 |
10 | for (start = 0; start < total; start = start + count) {
11 | count = (start + count > total)?total-start:count;
12 | var url = 'https://api.douban.com/v2/book/user/' +
13 | config.douban.user +
14 | '/collections?status=read&start='+start+'&count='+count;
15 |
16 | var res = request(url, {
17 | dataType: 'json'
18 | });
19 |
20 | count = res.data.count;
21 | total = res.data.total;
22 |
23 | var collections = res.data.collections;
24 |
25 | for (var i = 0; i < count; i++) {
26 | if(collections[i])
27 | {
28 | if(!collections[i].comment)
29 | {
30 | collections[i].comment="没有评论"
31 | }
32 | contents += "