Skip to content

Commit

Permalink
fix(autodiscovery): disable if empty post
Browse files Browse the repository at this point in the history
  • Loading branch information
curbengh committed Nov 17, 2019
1 parent ea4d764 commit e8338a7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/autodiscovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ function autodiscoveryInject(data) {
const path = feed.path;
let autodiscoveryTag = '';

if (data.match(/type=['|"]?application\/(atom|rss)\+xml['|"]?/i)) return;
if (data.match(/type=['|"]?application\/(atom|rss)\+xml['|"]?/i) || feed.autodiscovery === false) return;

type.forEach((feedType, i) => {
autodiscoveryTag += `<link rel="alternate" href="${url_for.call(this, path[i])}" `
Expand Down
1 change: 1 addition & 0 deletions lib/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ module.exports = function(locals, type, path) {
});

if (posts.length <= 0) {
feedConfig.autodiscovery = false;
return;
}

Expand Down
15 changes: 13 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,11 +355,11 @@ describe('Autodiscovery', () => {
};
hexo.config.feed = {
type: ['atom'],
path: ['atom.xml']
path: ['atom.xml'],
autodiscovery: true
};
hexo.config = Object.assign(hexo.config, urlConfig);


it('default', () => {
const content = '<head><link></head>';
const result = autoDiscovery(content).trim();
Expand All @@ -370,6 +370,17 @@ describe('Autodiscovery', () => {
$('link[type="application/atom+xml"]').attr('title').should.eql(hexo.config.title);
});

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

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

hexo.config.feed.autodiscovery = true;
});

it('prepend root', () => {
hexo.config.root = '/root/';
const content = '<head><link></head>';
Expand Down

0 comments on commit e8338a7

Please sign in to comment.