chore(core): move hexo generators to external pkg
parent
2063ab6261
commit
a222d5a845
|
@ -26,6 +26,8 @@ module.exports = hexo => {
|
||||||
if (missingDeps && missingDeps.length) {
|
if (missingDeps && missingDeps.length) {
|
||||||
logger.error('Please install the missing dependencies your Hexo site root directory:');
|
logger.error('Please install the missing dependencies your Hexo site root directory:');
|
||||||
logger.error(green('npm install --save ' + missingDeps.map(name => `${name}@${packageInfo.peerDependencies[name]}`).join(' ')));
|
logger.error(green('npm install --save ' + missingDeps.map(name => `${name}@${packageInfo.peerDependencies[name]}`).join(' ')));
|
||||||
|
logger.error('or:');
|
||||||
|
logger.error(green('yarn add ' + missingDeps.map(name => `${name}@${packageInfo.peerDependencies[name]}`).join(' ')));
|
||||||
process.exit(-1);
|
process.exit(-1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,34 +0,0 @@
|
||||||
const pagination = require('hexo-pagination');
|
|
||||||
|
|
||||||
module.exports = function(hexo) {
|
|
||||||
// ATTENTION: This will override the default category generator!
|
|
||||||
hexo.extend.generator.register('category', function(locals) {
|
|
||||||
const config = this.config;
|
|
||||||
const perPage = config.category_generator.per_page;
|
|
||||||
const paginationDir = config.pagination_dir || 'page';
|
|
||||||
|
|
||||||
function findParent(category) {
|
|
||||||
let parents = [];
|
|
||||||
if (typeof category === 'object' && 'parent' in category) {
|
|
||||||
const parent = locals.categories.filter(cat => cat._id === category.parent).first();
|
|
||||||
parents = [parent].concat(findParent(parent));
|
|
||||||
}
|
|
||||||
return parents;
|
|
||||||
}
|
|
||||||
|
|
||||||
return locals.categories.reduce((result, category) => {
|
|
||||||
const posts = category.posts.sort('-date');
|
|
||||||
const data = pagination(category.path, posts, {
|
|
||||||
perPage: perPage,
|
|
||||||
layout: ['category', 'archive', 'index'],
|
|
||||||
format: paginationDir + '/%d/',
|
|
||||||
data: {
|
|
||||||
category: category.name,
|
|
||||||
parents: findParent(category)
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return result.concat(data);
|
|
||||||
}, []);
|
|
||||||
});
|
|
||||||
};
|
|
|
@ -1,43 +0,0 @@
|
||||||
const util = require('hexo-util');
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Insight search content.json generator.
|
|
||||||
*/
|
|
||||||
module.exports = function(hexo) {
|
|
||||||
hexo.extend.generator.register('insight', function(locals) {
|
|
||||||
const url_for = hexo.extend.helper.get('url_for').bind(this);
|
|
||||||
function minify(str) {
|
|
||||||
return util.stripHTML(str).trim().replace(/\n/g, ' ').replace(/\s+/g, ' ')
|
|
||||||
.replace(/&#x([\da-fA-F]+);/g, (match, hex) => {
|
|
||||||
return String.fromCharCode(parseInt(hex, 16));
|
|
||||||
})
|
|
||||||
.replace(/&#([\d]+);/g, (match, dec) => {
|
|
||||||
return String.fromCharCode(dec);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
function postMapper(post) {
|
|
||||||
return {
|
|
||||||
title: post.title,
|
|
||||||
text: minify(post.content),
|
|
||||||
link: url_for(post.path)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
function tagMapper(tag) {
|
|
||||||
return {
|
|
||||||
name: tag.name,
|
|
||||||
slug: tag.slug,
|
|
||||||
link: url_for(tag.path)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
const site = {
|
|
||||||
pages: locals.pages.map(postMapper),
|
|
||||||
posts: locals.posts.map(postMapper),
|
|
||||||
tags: locals.tags.map(tagMapper),
|
|
||||||
categories: locals.categories.map(tagMapper)
|
|
||||||
};
|
|
||||||
return {
|
|
||||||
path: '/content.json',
|
|
||||||
data: JSON.stringify(site)
|
|
||||||
};
|
|
||||||
});
|
|
||||||
};
|
|
|
@ -3,10 +3,10 @@ const logger = require('hexo-log')();
|
||||||
module.exports = hexo => {
|
module.exports = hexo => {
|
||||||
logger.info('=== Registering Hexo extensions ===');
|
logger.info('=== Registering Hexo extensions ===');
|
||||||
require('hexo-component-inferno/lib/hexo/filter/locals')(hexo);
|
require('hexo-component-inferno/lib/hexo/filter/locals')(hexo);
|
||||||
require('./hexo/generator/category')(hexo);
|
|
||||||
require('hexo-component-inferno/lib/hexo/generator/assets')(hexo);
|
require('hexo-component-inferno/lib/hexo/generator/assets')(hexo);
|
||||||
require('hexo-component-inferno/lib/hexo/generator/insight')(hexo);
|
require('hexo-component-inferno/lib/hexo/generator/insight')(hexo);
|
||||||
require('hexo-component-inferno/lib/hexo/generator/categories')(hexo);
|
require('hexo-component-inferno/lib/hexo/generator/categories')(hexo);
|
||||||
|
require('hexo-component-inferno/lib/hexo/generator/category')(hexo);
|
||||||
require('hexo-component-inferno/lib/hexo/generator/tags')(hexo);
|
require('hexo-component-inferno/lib/hexo/generator/tags')(hexo);
|
||||||
require('hexo-component-inferno/lib/hexo/helper/cdn')(hexo);
|
require('hexo-component-inferno/lib/hexo/helper/cdn')(hexo);
|
||||||
require('hexo-component-inferno/lib/hexo/helper/page')(hexo);
|
require('hexo-component-inferno/lib/hexo/helper/page')(hexo);
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
"bulma-stylus": "0.8.0",
|
"bulma-stylus": "0.8.0",
|
||||||
"deepmerge": "^4.2.2",
|
"deepmerge": "^4.2.2",
|
||||||
"hexo": "^4.2.0",
|
"hexo": "^4.2.0",
|
||||||
"hexo-component-inferno": "^0.3.0",
|
"hexo-component-inferno": "^0.4.0",
|
||||||
"hexo-log": "^1.0.0",
|
"hexo-log": "^1.0.0",
|
||||||
"hexo-pagination": "^1.0.0",
|
"hexo-pagination": "^1.0.0",
|
||||||
"hexo-renderer-inferno": "^0.1.3",
|
"hexo-renderer-inferno": "^0.1.3",
|
||||||
|
|
Loading…
Reference in New Issue