Skip to content

Commit

Permalink
Merge pull request #3129 from h404bi/feature/meta-generator
Browse files Browse the repository at this point in the history
Misc: add meta generator injection filter
  • Loading branch information
segayuu authored Apr 20, 2018
2 parents 373b9c7 + 3ed25c9 commit 30fcc4f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/plugins/filter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ module.exports = ctx => {

filter.register('new_post_path', require('./new_post_path'));
filter.register('post_permalink', require('./post_permalink'));
filter.register('after_render:html', require('./meta_generator'));
};
17 changes: 17 additions & 0 deletions lib/plugins/filter/meta_generator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict';

let cheerio;
const hexoGeneratorTag = '<meta name="generator" content="Hexo %s" />';

function hexoMetaGeneratorInject(data) {
if (!cheerio) cheerio = require('cheerio');
const $ = cheerio.load(data, {decodeEntities: false});

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

return $.html();
}
}

module.exports = hexoMetaGeneratorInject;

0 comments on commit 30fcc4f

Please sign in to comment.