Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use `Cache` to determine if filter is enabled #4056

Open
jiangtj opened this issue Jan 5, 2020 · 2 comments · May be fixed by #4070 or #4078
Open

Use `Cache` to determine if filter is enabled #4056

jiangtj opened this issue Jan 5, 2020 · 2 comments · May be fixed by #4070 or #4078

Comments

@jiangtj
Copy link
Contributor

@jiangtj jiangtj commented Jan 5, 2020

Check List

Please check followings before submitting a new feature request.

  • I have already read Docs page
  • I have already searched existing issues

Feature Request

https://github.com/hexojs/hexo/blob/master/lib/plugins/filter/after_render/meta_generator.js

Currently, the meta_generator filter has performance problems. It is recommended to use a helper, but regular matching will still be used.

Maybe use Cache is a good solution.

function metaGeneratorHelper() {
  cache.set('meta_generator', true);
  return `<meta name="generator" content="Hexo ${this.env.version}">`;
}
function hexoMetaGeneratorInject(data) {
  let flag = cache.get('meta_generator');
  if (flag) return;
  const { config } = this;
  //...
}

Others

#4047 Inject can also do this, if use helpers in the theme, can improve performance.

@SukkaW

This comment has been minimized.

Copy link
Member

@SukkaW SukkaW commented Jan 10, 2020

I assume what you mean is a global plugins' status manager.

@SukkaW

This comment has been minimized.

Copy link
Member

@SukkaW SukkaW commented Jan 10, 2020

We could add this.prop = {} into helper's constructor(), And set ctx.extend.helper.prop.meta_generator = true inside meta_generator().

Later in meta_generator filter we could read this.extend.helper.prop.meta_generator to determine if meta_generator() helper is used or not.

@SukkaW SukkaW linked a pull request that will close this issue Jan 10, 2020
2 of 2 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.