Skip to content

Commit

Permalink
Misc: add meta generator injection filter
Browse files Browse the repository at this point in the history
  • Loading branch information
h404bi committed Apr 20, 2018
1 parent 373b9c7 commit 017d355
Show file tree
Hide file tree
Showing 2 changed files with 19 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'));
};
18 changes: 18 additions & 0 deletions lib/plugins/filter/meta_generator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';

const rMetaGenerator = /<meta\s+name=['|"]?generator['|"]?/i;
const hexoGeneratorTag = '<meta name="generator" content="Hexo %s" />';
let cheerio;

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

$('head').prepend(hexoGeneratorTag.replace('%s', this.version));

return $.html();
}
}

module.exports = hexoMetaGeneratorInject;

0 comments on commit 017d355

Please sign in to comment.