2015-05-09 17:36:15 +08:00
|
|
|
module.exports = function(nico) {
|
|
|
|
var exports = {};
|
|
|
|
|
|
|
|
exports.reader = function(post) {
|
|
|
|
var filename = post.meta.filepath.toLowerCase();
|
|
|
|
if (filename.indexOf('components') >= 0) {
|
|
|
|
post.template = post.meta.template = 'component';
|
|
|
|
} else {
|
|
|
|
post.template = post.meta.template = (post.meta.template || 'page');
|
|
|
|
}
|
|
|
|
if (filename === 'readme.md') {
|
|
|
|
post.filename = post.meta.filename = 'index';
|
|
|
|
post.meta.category = 'docs';
|
|
|
|
}
|
|
|
|
post.meta.category = post.meta.category || post.meta.directory;
|
|
|
|
return post;
|
|
|
|
};
|
|
|
|
|
|
|
|
exports.filters = {
|
|
|
|
find_category: function(pages, cat) {
|
|
|
|
var ret = [];
|
|
|
|
Object.keys(pages).forEach(function(key) {
|
|
|
|
var item = nico.sdk.post.read(key);
|
|
|
|
if (item.meta.category === cat) {
|
|
|
|
ret.push(item);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
ret = ret.sort(function(a, b) {
|
|
|
|
if (/index$/i.test(a.filename)) {
|
|
|
|
a.meta.order = 1;
|
|
|
|
}
|
|
|
|
if (/index$/i.test(b.filename)) {
|
|
|
|
b.meta.order = 1;
|
|
|
|
}
|
|
|
|
a = a.meta.order || 10;
|
|
|
|
b = b.meta.order || 10;
|
|
|
|
return parseInt(a, 10) - parseInt(b, 10);
|
|
|
|
});
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return exports;
|
2015-05-07 18:50:36 +08:00
|
|
|
};
|