Skip to content

Commit

Permalink
Merge 11c85de into bbc2f04
Browse files Browse the repository at this point in the history
  • Loading branch information
curbengh committed Oct 28, 2018
2 parents bbc2f04 + 11c85de commit c6007c8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/plugins/filter/meta_generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function hexoMetaGeneratorInject(data) {
if (!cheerio) cheerio = require('cheerio');
const $ = cheerio.load(data, {decodeEntities: false});

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

return $.html();
Expand Down
1 change: 1 addition & 0 deletions test/scripts/filters/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ describe('Filters', () => {
require('./excerpt');
require('./external_link');
require('./i18n_locals');
require('./meta_generator');
require('./new_post_path');
require('./post_permalink');
require('./render_post');
Expand Down
36 changes: 36 additions & 0 deletions test/scripts/filters/meta_generator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
'use strict';

const should = require('chai').should(); // eslint-disable-line

describe('Meta Generator', function() {
const Hexo = require('../../../lib/hexo');
const hexo = new Hexo();
const metaGenerator = require('../../../lib/plugins/filter/meta_generator').bind(hexo);
const cheerio = require('cheerio');

it('default', function() {
let content = `<head><link></head>`;

let data = {
content: content
};

metaGenerator(data);
const $ = cheerio.load(data);
$('meta[name="generator"]').length.should.eql(1);
});

it('empty <head>', function() {
let content = `<head></head>`;

let data = {
content: content
};

metaGenerator(data);
const $ = cheerio.load(data);
// meta generator should not be prepended if <head> tag is empty
// see https://github.com/hexojs/hexo/pull/3315
$('meta[name="generator"]').length.should.eql(0);
});
});

0 comments on commit c6007c8

Please sign in to comment.