From 7e25de703f825c2bf63c98cc199c07b88030a501 Mon Sep 17 00:00:00 2001 From: xiazeyu_2011 Date: Fri, 30 Mar 2018 21:52:47 +0800 Subject: [PATCH] perf: better RegExp from hexo-inject fix #96 --- index.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/index.js b/index.js index 29d5f1c..b21f775 100755 --- a/index.js +++ b/index.js @@ -180,17 +180,13 @@ if (config.enable) { /* * Injector borrowed form here: * https://github.com/Troy-Yang/hexo-lazyload-image/blob/master/lib/addscripts.js - * TODO: - * use cheerio to modify DOM - * failed in 2018.3.18 - * https://github.com/cheeriojs/cheerio/issues/1031 */ hexo.extend.filter.register('after_render:html', (htmlContent) => { const scriptToInject = `L2Dwidget.init(${JSON.stringify(config)});`; const contentToInject = ``; let newHtmlContent = htmlContent; - if (/<\/body>/gi.test(htmlContent)) { + if (/([\n\r\s\t]*<\/body>)/i.test(htmlContent)) { const lastIndex = htmlContent.lastIndexOf(''); newHtmlContent = `${htmlContent.substring(0, lastIndex)}${contentToInject}${htmlContent.substring(lastIndex, htmlContent.length)}`;