Skip to content

Commit

Permalink
Add index
Browse files Browse the repository at this point in the history
  • Loading branch information
xcatliu committed Jun 23, 2016
1 parent cc64f99 commit b64333a
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .eslintrc
@@ -0,0 +1,6 @@
{
"extends": "airbnb-base",
"rules": {
"import/no-unresolved": 0
}
}
1 change: 1 addition & 0 deletions .gitignore
@@ -0,0 +1 @@
node_modules
30 changes: 30 additions & 0 deletions README.md
@@ -0,0 +1,30 @@
# hexo-generator-index-i18n

> I18n index generator plugin for Hexo.
Impressed by [hexo-generator-index] and [hexo-generator-i18n](https://github.com/Jamling/hexo-generator-i18n).

## Installation

```shell
$ npm install hexo-generator-index-i18n --save
```

## Options

Use the same options as [hexo-generator-index]:

```yml
index_generator:
per_page: 10
order_by: -date
```

- **per_page**: Posts displayed per page. (0 = disable pagination)
- **order_by**: Posts order. (Order by date descending by default)

## License

MIT

[hexo-generator-index]: https://github.com/hexojs/hexo-generator-index
26 changes: 26 additions & 0 deletions index.js
@@ -0,0 +1,26 @@
/* global hexo */
const assign = require('object-assign');
const pagination = require('hexo-pagination');

hexo.config.index_generator = assign({
per_page: typeof hexo.config.per_page === 'undefined' ? 10 : hexo.config.per_page,
order_by: '-date',
}, hexo.config.index_generator);

hexo.extend.generator.register('index-i18n', function (locals) {
const config = this.config;
const posts = locals.posts.sort(config.index_generator.order_by);
const paginationDir = config.pagination_dir || 'page';

return config.language.filter(lang => lang !== 'default').reduce((prev, lang) => {
const filtedPosts = posts.filter(item => item.lang === lang);
return prev.concat(pagination(lang, filtedPosts, {
perPage: config.index_generator.per_page,
layout: ['index'],
format: `${paginationDir}/%d/`,
data: {
__index: true,
},
}));
}, []);
});
36 changes: 36 additions & 0 deletions package.json
@@ -0,0 +1,36 @@
{
"name": "hexo-generator-index-i18n",
"version": "0.1.0",
"description": "I18n index generator plugin for Hexo",
"main": "index.js",
"scripts": {
"lint": "eslint . && echo 'ESLint Passed!\\n'",
"test": "npm run lint"
},
"repository": {
"type": "git",
"url": "git+https://github.com/xcatliu/hexo-generator-index-i18n.git"
},
"keywords": [
"hexo",
"generator",
"index",
"i18n",
"home"
],
"author": "xcatliu <xcatliu@gmail.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/xcatliu/hexo-generator-index-i18n/issues"
},
"homepage": "https://github.com/xcatliu/hexo-generator-index-i18n#readme",
"dependencies": {
"hexo-pagination": "^0.1.0",
"object-assign": "^4.1.0"
},
"devDependencies": {
"eslint": "^2.13.1",
"eslint-config-airbnb-base": "^3.0.1",
"eslint-plugin-import": "^1.8.1"
}
}

0 comments on commit b64333a

Please sign in to comment.