ant-design/theme/theme.js

67 lines
1.7 KiB
JavaScript
Raw Normal View History

2015-05-11 18:09:13 +08:00
var _ = require('lodash');
2015-05-09 17:36:15 +08:00
module.exports = function(nico) {
var exports = {};
exports.reader = function(post) {
2015-05-12 17:50:03 +08:00
var filepath = post.meta.filepath.toLowerCase();
if (filepath.indexOf('components') === 0) {
2015-05-09 17:36:15 +08:00
post.template = post.meta.template = 'component';
} else {
post.template = post.meta.template = (post.meta.template || 'page');
}
2015-05-12 17:50:03 +08:00
if (filepath === 'readme.md') {
2015-05-09 17:36:15 +08:00
post.filename = post.meta.filename = 'index';
}
2015-05-15 16:00:08 +08:00
if (filepath.indexOf('/demo/') > 0) {
post.template = post.meta.template = 'code';
}
2015-05-09 17:36:15 +08:00
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;
2015-05-11 18:09:13 +08:00
},
get_all_category: function(pages) {
return _.uniq(Object.keys(pages).map(function(key) {
var item = nico.sdk.post.read(key);
return item.meta.category;
}).filter(function(item) {
return item;
}));
2015-05-16 15:03:33 +08:00
},
under: function(pages, directory) {
var ret = [];
Object.keys(pages).forEach(function(key) {
var page = pages[key];
console.log(key, directory);
if (key.indexOf(directory + '/demo/') === 0) {
ret.push(page);
}
});
return ret;
2015-05-09 17:36:15 +08:00
}
};
return exports;
2015-05-07 18:50:36 +08:00
};