Skip to content

Commit

Permalink
fix only exclude works wrong issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamling committed Mar 1, 2018
1 parent 1cee9fc commit b5f94d0
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 10 deletions.
54 changes: 47 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,29 @@ Don't worry about the uninstallation, this plugin works same as offical index ge
## Options

``` yaml
# whether the index2 generator include the index generator, default is true
# whether the hexo-generator-index2 include the offical hexo-generator-index, default is true
index2_include_index: true # defult is true

# the custom index2 generator, can be array or object
index2_generator:
- layout: 'index' # use existing index layout
path: 'example' # output to example folder
- layout: 'archive' # use existing archive layout
path: 'web' # output to web folder: http://127.0.0.1:4000/
per_page: 10
order_by: -date
include:
- category Web # include article which category is Web
exclude:
- tag Hexo # exclude article which tag is Hexo
- layout: 'index'
path: 'news' # output to news folder
include: category Android
- layout: 'index' # use existing index layout
path: '' # output to root directory: http://127.0.0.1:4000/
index: true # Set whether index, results is_home() is true or not
```
- **per_page**: Posts displayed per page. (0 = disable pagination)
- **order_by**: Posts order. (Order by date descending by default)
- **layout**: Set the layout, default is `index`
- **path**: Output path, if path is `''`, means output to the root directory (http://127.0.0.1:4000/ )
- **index**: Home index or not, if `true` and the `path` is `''`, same to offical [hexo-generator-index]
- **include**: Posts filter include option
- **exclude**: Posts filter exclude option

Expand All @@ -55,6 +58,42 @@ Include/exclude option is `attribute value` format, available attribute are:

## Usage

### Advance offical [hexo-generator-index]

Simply
``` yaml
# whether the hexo-generator-index2 include the offical hexo-generator-index, default is true
index2_include_index: true # defult is true
```

Advance
``` yaml
index2_generator:
- layout: 'index' # use existing index layout
path: '' # output to root directory: http://127.0.0.1:4000/
index: true # Set index true
include: # include some path/category/tag
- category Web # include article which category is Web
exclude: # excluce some path/category/tag
- tag Hexo # exclude article which tag is Hexo
```

### Special

Generate special articles to specific folder. Such as list articles witch category is `Web` to http://127.0.0.1/web/

``` yaml
index2_generator:
- layout: 'index' # use existing archive layout
path: 'web' # output to web folder: http://127.0.0.1:4000/
per_page: 10
order_by: -date
include:
- category Web # include article which category is Web
```

### is_home2()

Use `is_home2()` to judge whether the page is generated by index2 generator.

```
Expand All @@ -72,5 +111,6 @@ Use `is_home2()` to judge whether the page is generated by index2 generator.
## License
MIT
[hexo-generator-index]: https://github.com/hexojs/hexo-generator-index
[hexo-generator-index2]: https://github.com/Jamling/hexo-generator-index2
[Hexo]: http://hexo.io/
9 changes: 8 additions & 1 deletion README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ $ npm install hexo-generator-index2 --save
$ npm uninstall hexo-generator-index --save
```

[hexo-generator-index2]可以完全替代官方的[hexo-generator-index],所以安装之后,先卸载官方的插件,不然会引起一些冲突。

## 选项

``` yaml
# index2 generator是否包含官方的index generator,默认true(包含)
# index2 generator是否包含官方的hexo-generator-index,默认true(包含)
index2_include_index: true # defult is true

# 配置index2 generator,可以是数组或对象
Expand All @@ -37,6 +39,9 @@ index2_generator:

- **per_page**: Posts displayed per page. (0 = disable pagination)
- **order_by**: Posts order. (Order by date descending by default)
- **layout**: Set the layout, default is `index`
- **path**: Output path, if path is `''`, means output to the root directory (http://127.0.0.1:4000/ )
- **index**: Home index or not, if `true` and the `path` is `''`, same to offical [hexo-generator-index]
- **include**: Posts filter include option
- **exclude**: Posts filter exclude option

Expand All @@ -53,4 +58,6 @@ Include/exclude 选项格式为`属性 值`(注意,属性与值中间有个

MIT

[hexo-generator-index]: https://github.com/hexojs/hexo-generator-index
[hexo-generator-index2]: https://github.com/Jamling/hexo-generator-index2
[Hexo]: http://hexo.io/
7 changes: 5 additions & 2 deletions lib/generator2.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ module.exports = function (locals) {
}
}
}
else {
ret = true;
}
if (exclude.length > 0) {
var ex = false;
for (var i = 0; i < exclude.length; i++) {
Expand Down Expand Up @@ -96,8 +99,8 @@ module.exports = function (locals) {
}

this.config.index2_generators.forEach(function (g) {
_self.log.info(JSON.stringify(g));
//_self.log.info(JSON.stringify(g));
_generate(_self, locals, g);
});
return ret;
};
};

0 comments on commit b5f94d0

Please # to comment.