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

feat: add option to disable meta generator tag #3653

Merged
merged 2 commits into from
Aug 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/hexo/default_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ module.exports = {
deploy: {},

// ignore files from processing
ignore: []
ignore: [],

// Category & Tag
meta_generator: true
};

5 changes: 4 additions & 1 deletion lib/plugins/filter/meta_generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ const hexoGeneratorTag = '<meta name="generator" content="Hexo %s" />';
function hexoMetaGeneratorInject(data) {
if (!cheerio) cheerio = require('cheerio');
const $ = cheerio.load(data, {decodeEntities: false});
const { config } = this;

if (!($('meta[name="generator"]').length > 0) && $('head').contents().length > 0) {
if (!($('meta[name="generator"]').length > 0) &&
$('head').contents().length > 0 &&
config.meta_generator) {
$('head').prepend(hexoGeneratorTag.replace('%s', this.version));

return $.html();
Expand Down
9 changes: 9 additions & 0 deletions test/scripts/filters/meta_generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,13 @@ describe('Meta Generator', () => {
const resultType = typeof result;
resultType.should.eql('undefined');
});

it('disable meta_generator', () => {
const content = '<head><link></head>';
hexo.config.meta_generator = false;
const result = metaGenerator(content);

const resultType = typeof result;
resultType.should.eql('undefined');
});
});