├── .eslintignore ├── .eslintrc ├── .gitignore ├── .jscsrc ├── .npmignore ├── index.js ├── .travis.yml ├── LICENSE ├── lib └── generator.js ├── package.json └── README.md /.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | coverage/ 3 | tmp/ -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "hexo", 3 | "root": true 4 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules/ 3 | tmp/ 4 | *.log 5 | .idea/ 6 | coverage/ -------------------------------------------------------------------------------- /.jscsrc: -------------------------------------------------------------------------------- 1 | { 2 | "excludeFiles": ["node_modules/**", "coverage/**", "tmp/**"], 3 | "preset": "hexo" 4 | } -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | test/ 2 | tmp/ 3 | coverage/ 4 | *.log 5 | .travis.yml 6 | gulpfile.js 7 | .idea/ 8 | appveyor.yml -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | /* global hexo */ 2 | 3 | 'use strict'; 4 | 5 | var assign = require('object-assign'); 6 | 7 | hexo.config.index_generator = assign({ 8 | per_page: typeof hexo.config.per_page === 'undefined' ? 10 : hexo.config.per_page, 9 | order_by: '-date' 10 | }, hexo.config.index_generator); 11 | 12 | hexo.extend.generator.register('index', require('./lib/generator')); 13 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | 3 | sudo: false 4 | 5 | cache: 6 | apt: true 7 | directories: 8 | - node_modules 9 | 10 | node_js: 11 | - "0.12" 12 | - "4" 13 | - "5" 14 | 15 | script: 16 | - npm run eslint 17 | - npm run jscs 18 | - npm run test-cov 19 | 20 | after_script: 21 | - npm install coveralls 22 | - cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 Tommy Chen 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /lib/generator.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | var pagination = require('hexo-pagination'); 4 | var moment = require('moment'); 5 | 6 | module.exports = function(locals) { 7 | var config = this.config; 8 | var posts = locals.posts; 9 | var paginationDir = config.index_generator_plus.pagination_dir || 'page'; 10 | var path = config.index_generator_plus.path || ''; 11 | 12 | posts.data = posts.data.sort(function(a, b) { 13 | !a.top && (a.top = 0); 14 | !b.top && (b.top = 0); 15 | 16 | // `date` has been deal with moment.js, so `updateDate` also need to be momented. 17 | a.updateDate ? (a.updateDate = moment(a.updateDate)) : (a.updateDate = a.date); 18 | b.updateDate ? (b.updateDate = moment(b.updateDate)) : (b.updateDate = b.date); 19 | 20 | // `top` No.1 priority, `updateDate` No.2, `date` the last. 21 | if(a.top == b.top){ 22 | return b.updateDate - a.updateDate; 23 | }else{ 24 | return b.top - a.top; 25 | } 26 | }); 27 | 28 | return pagination(path, posts, { 29 | perPage: config.index_generator_plus.per_page, 30 | layout: ['index', 'archive'], 31 | format: paginationDir + '/%d/', 32 | data: { 33 | __index: true 34 | } 35 | }); 36 | }; 37 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hexo-generator-index-plus", 3 | "version": "1.0.0", 4 | "description": "Index generator plus for Hexo, which includes Top and UpdateDate.", 5 | "main": "index", 6 | "scripts": { 7 | "eslint": "eslint .", 8 | "jscs": "jscs .", 9 | "test": "mocha test/index.js", 10 | "test-cov": "istanbul cover --print both _mocha -- test/index.js" 11 | }, 12 | "directories": { 13 | "lib": "./lib" 14 | }, 15 | "engines": { 16 | "node": ">= 0.10.0" 17 | }, 18 | "repository": "YuyingWu/hexo-generator-index-plus", 19 | "homepage": "https://github.com/YuyingWu/hexo-generator-index-plus/blob/master/README.md", 20 | "keywords": [ 21 | "hexo", 22 | "generator", 23 | "index", 24 | "home", 25 | "top", 26 | "updateDate" 27 | ], 28 | "author": "Yuying Wu (http://demo.wuyuying.com/)", 29 | "license": "MIT", 30 | "devDependencies": { 31 | "chai": "^3.4.0", 32 | "eslint": "^1.8.0", 33 | "eslint-config-hexo": "^1.0.2", 34 | "hexo": "^3.0.0", 35 | "istanbul": "^0.4.0", 36 | "jscs": "^2.5.0", 37 | "jscs-preset-hexo": "^1.0.1", 38 | "mocha": "^2.0.1" 39 | }, 40 | "dependencies": { 41 | "hexo-pagination": "0.0.2", 42 | "moment": "^2.18.1", 43 | "object-assign": "^4.0.1" 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # hexo-generator-index-plus 2 | 3 | Index generator plus for [Hexo], which includes `top` and `updateDate` order rules. 4 | 5 | [ **!!! Important** ] 6 | Please update your `hexo-generator-index-plus` to version 1.0.0+, cuz there is a bug for `updateDate` in beta versions under 1.0.0. 7 | 8 | ## Installation 9 | 10 | ``` bash 11 | $ npm install hexo-generator-index-plus --save 12 | ``` 13 | 14 | * remove default generator `hexo-generator-index` 15 | * update hexo-cli's assets dependencies, from `hexo-generator-index` to `hexo-generator-index-plus`, node_modules/hexo-cli/assets/package.json 16 | 17 | ## Options 18 | 19 | Default order rules: 20 | `top` descending -> `updateDate` descending -> `date` descending 21 | 22 | ``` yaml 23 | index_generator_plus: 24 | path: '' 25 | per_page: 10 26 | ``` 27 | - **path**: Root path for your blogs index page. (default = '') 28 | - **per_page**: Posts displayed per page. (0 = disable pagination) 29 | 30 | [ more to do for the next version ] 31 | - **order_by**: descend(default) | ascend 32 | 33 | ## Front-matter 34 | 35 | ``` 36 | title: Blog Log 37 | tags: 38 | - blog 39 | categories: 40 | - tech 41 | date: 2015-04-23 00:35:45 42 | updateDate: 2017-04-02 15:13:00 43 | top: 1 44 | ``` 45 | - **top**: No.1 priority for post order. The higher, the topper. 46 | - **updateDate**:anthoer date instead of create date, which you want to highlight.(No.2 priority) 47 | - **date**: create time of the post, the default comparing attribute. 48 | 49 | ## License 50 | 51 | MIT 52 | --------------------------------------------------------------------------------