Skip to content

Commit

Permalink
Merge pull request #3653 from curbengh/meta-generator
Browse files Browse the repository at this point in the history
feat: add option to disable meta generator tag
  • Loading branch information
yoshinorin committed Aug 6, 2019
2 parents 9b87047 + 5d592cc commit 0621184
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
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');
});
});

0 comments on commit 0621184

Please sign in to comment.