-
-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
feat: add prop to helper extension #4070
Conversation
|| data.match(/<meta([\s]+|[\s]+[^<>]+[\s]+)name=['|"]?generator['|"]?/i)) return; | ||
const { config, version } = this; | ||
|
||
const needInject = cache.apply('need-inject', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just assume meta[name="generator"]
will be inserted to every page if meta_generator()
is used or <meta name="generator" content="Hexo [version]">
is manually added in the theme. So it is fine to cache this.
@@ -1,13 +1,24 @@ | |||
'use strict'; | |||
|
|||
const { Cache } = require('hexo-util'); | |||
const cache = new Cache(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using local val is enough.
let needInject;
...
function hexoMetaGeneratorInject(data) {
const { config } = this;
if (typeof needInject !== 'boolean') {
needInject = !(!config.meta_generator
|| this.extend.helper.getProp('meta_generator')
|| data.match(/<meta([\s]+|[\s]+[^<>]+[\s]+)name=['|"]?generator['|"]?/i));
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMHO, use cache.apply
here made code more readable since cache.apply
support caching return value of given function.
lib/plugins/helper/meta_generator.js
Outdated
module.exports = metaGeneratorHelper; | ||
module.exports = ctx => { | ||
return () => { | ||
if (!ctx.extend.helper.getProp('meta_generator')) ctx.extend.helper.setProp('meta_generator', true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest use_meta_generator_helper
as the property name.
If meta_generator
is used, we don't know what this means.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change to meta_generator_helper_used
1df1d89
to
7eede38
Compare
What does it do?
Fix #4056. Close #3919.
Automatically disable
meta_generator
filter ifmeta_generator()
is used.cc @curbengh @jiangtj
How to test
Screenshots
Pull request tasks