From 7326878b4135d8e273ca1ff0a03ae4d38aaf29a0 Mon Sep 17 00:00:00 2001 From: ppoffice Date: Thu, 15 Aug 2019 00:05:21 -0400 Subject: [PATCH] fix(*): fix oom by removing meta generator --- includes/helpers/override.js | 26 +++++++++++++++++++------- includes/helpers/site.js | 7 ++++++- layout/common/head.ejs | 7 +++++-- scripts/index.js | 8 ++++++++ 4 files changed, 38 insertions(+), 10 deletions(-) diff --git a/includes/helpers/override.js b/includes/helpers/override.js index f245929..77a2835 100644 --- a/includes/helpers/override.js +++ b/includes/helpers/override.js @@ -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; }); /** diff --git a/includes/helpers/site.js b/includes/helpers/site.js index f9bd525..c29c187 100644 --- a/includes/helpers/site.js +++ b/includes/helpers/site.js @@ -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; + }); } \ No newline at end of file diff --git a/layout/common/head.ejs b/layout/common/head.ejs index bdbe1ab..3bb0ed5 100644 --- a/layout/common/head.ejs +++ b/layout/common/head.ejs @@ -1,7 +1,10 @@ - -<%= page_title() %> + +<% if (get_config('meta_generator', true)) { %> + +<% } %> <%- meta() %> +<%= page_title() %> <% if (has_config('open_graph')) { %> <%- open_graph({ diff --git a/scripts/index.js b/scripts/index.js index 1fd9e98..43a84f2 100644 --- a/scripts/index.js +++ b/scripts/index.js @@ -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)