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

Closed
2 tasks done
jiangtj opened this issue Jan 5, 2020 · 2 comments · Fixed by #4208
Closed
2 tasks done

Use Cache to determine if filter is enabled #4056

jiangtj opened this issue Jan 5, 2020 · 2 comments · Fixed by #4208
Labels
enhancement New feature or request feature-request

Comments

@jiangtj
Copy link
Member

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
Copy link
Member

SukkaW commented Jan 10, 2020

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

@SukkaW SukkaW added enhancement New feature or request feature-request labels Jan 10, 2020
@SukkaW
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feature-request
Projects
None yet
2 participants