Skip to content

Commit

Permalink
feat: return before data.replace if no inject
Browse files Browse the repository at this point in the history
  • Loading branch information
SukkaW committed Jan 5, 2020
1 parent 044dad5 commit 0213f5f
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions lib/plugins/filter/after_render/injector.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
+ '<!-- hexo injector ' + flag + ' start -->'
+ code
+ '<!-- hexo injector ' + flag + ' end -->';
}
return data.replace(pattern, str => {
const code = arr.reduce((a, c) => a + c, '');

return '<!-- hexo injector ' + flag + ' start -->'
if (isBegin) {
return str
+ '<!-- hexo injector ' + flag + ' start -->'
+ code
+ '<!-- hexo injector ' + flag + ' end -->'
+ str;
+ '<!-- hexo injector ' + flag + ' end -->';
}

return str;
return '<!-- hexo injector ' + flag + ' start -->'
+ code
+ '<!-- hexo injector ' + flag + ' end -->'
+ str;
});
}

Expand Down

0 comments on commit 0213f5f

Please sign in to comment.