├── .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 += "

" 42 | } 43 | }; 44 | contents +=""; 45 | }; 46 | 47 | return { 48 | path: 'douban/index.html', 49 | data: {title: '读书', content: contents, comments:true, slug:'douban'}, 50 | layout: 'post', 51 | }; 52 | }; 53 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hexo-generator-douban", 3 | "version": "0.1.2", 4 | "description": "Douban generator plugin for Hexo.", 5 | "main": "index.js", 6 | "dependencies": { 7 | "object-assign": "^2.0.0", 8 | "urllib-sync": "^1.0.1" 9 | }, 10 | "repository": { 11 | "type": "git", 12 | "url": "https://github.com/Yikun/hexo-generator-douban.git" 13 | }, 14 | "keywords": [ 15 | "generator", 16 | "hexo", 17 | "douban" 18 | ], 19 | "author": "Jiang Yikun", 20 | "bugs": { 21 | "url": "https://github.com/Yikun/hexo-generator-douban/issues" 22 | }, 23 | "homepage": "https://github.com/Yikun/hexo-generator-douban" 24 | } 25 | --------------------------------------------------------------------------------