fix(*): fix oom by removing meta generator

This commit is contained in:
ppoffice 2019-08-15 00:05:21 -04:00
parent f4d82a37ee
commit 7326878b41
4 changed files with 38 additions and 10 deletions

View File

@ -11,21 +11,30 @@
*/
const cheerio = require('cheerio');
const __archives = [];
const __categories = [];
const __tags = [];
module.exports = function (hexo) {
hexo.extend.helper.register('_list_archives', function () {
if (__archives.length) {
return __archives;
}
const $ = cheerio.load(this.list_archives(), { decodeEntities: false });
const archives = [];
$('.archive-list-item').each(function () {
archives.push({
__archives.push({
url: $(this).find('.archive-list-link').attr('href'),
name: $(this).find('.archive-list-link').text(),
count: $(this).find('.archive-list-count').text()
});
});
return archives;
return __archives;
});
hexo.extend.helper.register('_list_categories', function () {
if (__categories.length) {
return __categories;
}
const $ = cheerio.load(this.list_categories({ depth: 2 }), { decodeEntities: false });
function traverse(root) {
const categories = [];
@ -42,20 +51,23 @@ module.exports = function (hexo) {
});
return categories;
}
return traverse($('.category-list'));
__categories.push(...traverse($('.category-list')));
return __categories;
});
hexo.extend.helper.register('_list_tags', function () {
if (__tags.length) {
return __tags;
}
const $ = cheerio.load(this.list_tags(), { decodeEntities: false });
const tags = [];
$('.tag-list-item').each(function () {
tags.push({
__tags.push({
url: $(this).find('.tag-list-link').attr('href'),
name: $(this).find('.tag-list-link').text(),
count: $(this).find('.tag-list-count').text()
});
});
return tags;
return __tags;
});
/**

View File

@ -11,6 +11,7 @@
* <%- word_count(content) %>
* <%- md5(data) %>
* <%- meta() %>
* <%- hexo_version() %>
*/
const URL = require('url').URL;
const moment = require('moment');
@ -62,7 +63,7 @@ module.exports = function (hexo) {
});
hexo.extend.helper.register('md5', function (data) {
return crypto.createHash('md5').update(data).digest("hex")
return crypto.createHash('md5').update(data).digest("hex");
});
hexo.extend.helper.register('meta', function () {
@ -98,4 +99,8 @@ module.exports = function (hexo) {
});
return metaDOMArray.join('\n');
});
hexo.extend.helper.register('hexo_version', function (data) {
return hexo.version;
});
}

View File

@ -1,7 +1,10 @@
<meta charset="utf-8">
<title><%= page_title() %></title>
<meta charset="utf-8" />
<% if (get_config('meta_generator', true)) { %>
<meta name="generator" content="Hexo <%= hexo_version() %>" />
<% } %>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1" />
<%- meta() %>
<title><%= page_title() %></title>
<% if (has_config('open_graph')) { %>
<%- open_graph({

View File

@ -13,6 +13,14 @@ require('../includes/helpers/override')(hexo);
require('../includes/helpers/page')(hexo);
require('../includes/helpers/site')(hexo);
// Fix large blog rendering OOM
const postHtmlFilter = hexo.extend.filter.list()['after_render:html'];
for (let filter of postHtmlFilter) {
if (filter.name === 'hexoMetaGeneratorInject') {
hexo.extend.filter.unregister('after_render:html', filter);
}
}
// Debug helper
hexo.extend.helper.register('console', function () {
console.log(arguments)