forked from hexojs/hexo-generator-index
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For this generator to work the Hexo configuration must specify more than one language. This is part of #1.
- Loading branch information
Showing
3 changed files
with
163 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,35 @@ | ||
'use strict'; | ||
|
||
var _ = require('lodash'); | ||
var multilingual = require('hexo-multilingual'); | ||
var pagination = require('hexo-pagination'); | ||
|
||
module.exports = function(locals) { | ||
var config = this.config; | ||
var posts = locals.posts.sort(config.index_generator.order_by); | ||
var paginationDir = config.pagination_dir || 'page'; | ||
var result = []; | ||
|
||
return pagination('', posts, { | ||
perPage: config.index_generator.per_page, | ||
layout: ['index', 'archive'], | ||
format: paginationDir + '/%d/', | ||
data: { | ||
__index: true | ||
function _c(value, lang) { | ||
return multilingual.util._c(value, lang, config, locals); | ||
} | ||
|
||
_.forEach(config.language, function(lang) { | ||
if (lang != 'default') { | ||
var posts = locals.posts.sort(_c('index_generator.order_by', lang)).filter(function(post) { | ||
return post.lang == lang; | ||
}); | ||
var paginationDir = _c('pagination_dir', lang) || 'page'; | ||
|
||
result = result.concat(pagination(lang, posts, { | ||
perPage: _c('index_generator.per_page', lang), | ||
layout: ['index', 'archive'], | ||
format: paginationDir + '/%d/', | ||
data: { | ||
__index: true, | ||
lang: lang | ||
} | ||
})); | ||
} | ||
}); | ||
|
||
return result; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters