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; }); }