From 0213f5ff0299b6949689e41661c54b6cc8d7d0d1 Mon Sep 17 00:00:00 2001 From: SukkaW Date: Sun, 5 Jan 2020 22:49:05 +0800 Subject: [PATCH] feat: return before data.replace if no inject --- lib/plugins/filter/after_render/injector.js | 28 ++++++++++----------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/lib/plugins/filter/after_render/injector.js b/lib/plugins/filter/after_render/injector.js index 97cc3e844c..477f344dad 100644 --- a/lib/plugins/filter/after_render/injector.js +++ b/lib/plugins/filter/after_render/injector.js @@ -40,28 +40,26 @@ function injectFilter(data, locals = { page: {} }) { }; function injector(data, pattern, flag, isBegin = true) { - return data.replace(pattern, str => { - if (data.includes(`hexo injector ${flag}`)) return str; + if (data.includes(`hexo injector ${flag}`)) return data; - const arr = _Injector.get(flag).filter(i => is(i.to)).map(i => i.value); + const arr = _Injector.get(flag).filter(i => is(i.to)).map(i => i.value); - if (arr.length) { - const code = arr.reduce((a, c) => a + c, ''); + if (!arr.length) return data; - if (isBegin) { - return str - + '' - + code - + ''; - } + return data.replace(pattern, str => { + const code = arr.reduce((a, c) => a + c, ''); - return '' + if (isBegin) { + return str + + '' + code - + '' - + str; + + ''; } - return str; + return '' + + code + + '' + + str; }); }