From 066aafcf7ec0ba6b54700c81c249375032706ad5 Mon Sep 17 00:00:00 2001 From: Seha Date: Wed, 30 Oct 2019 11:23:17 +0900 Subject: [PATCH 1/9] Add : feed icon to rss2.xml I configured `feed.icon` in the `config.yml` file but that icon was not exposed when creating the feed xml file. So, I Add in rss2.xml ` {{(url + config.feed.icon) | uriencode}} ` and I see that it works. --- rss2.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/rss2.xml b/rss2.xml index 3fe7ac4..d2b1b56 100644 --- a/rss2.xml +++ b/rss2.xml @@ -4,6 +4,7 @@ xmlns:content="http://purl.org/rss/1.0/modules/content/"> {{ config.title }} + {{ (url+config.feed.icon) | uriencode }} {{ url }} {% if config.feed.hub %}{% endif %} From 46be47d122f8d2d3239f94fc32fed5e7147854ae Mon Sep 17 00:00:00 2001 From: sehajyang Date: Wed, 30 Oct 2019 16:54:55 +0900 Subject: [PATCH 2/9] Fix : generator.js, icon url can third-party url --- lib/generator.js | 12 ++++++------ rss2.xml | 2 +- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/generator.js b/lib/generator.js index 33b2e1e..935ba70 100644 --- a/lib/generator.js +++ b/lib/generator.js @@ -4,7 +4,7 @@ const nunjucks = require('nunjucks'); const env = new nunjucks.Environment(); const { join } = require('path'); const { readFileSync } = require('fs'); -const { encodeURL, gravatar } = require('hexo-util'); +const { encodeURL, gravatar, full_url_for } = require('hexo-util'); env.addFilter('uriencode', str => { return encodeURL(str); @@ -35,14 +35,14 @@ module.exports = function(locals) { if (url[url.length - 1] !== '/') url += '/'; let icon = ''; - if (feedConfig.icon) icon = url + encodeURI(feedConfig.icon); + if (feedConfig.icon) icon = encodeURI(full_url_for.call(this, feedConfig.icon)); else if (config.email) icon = gravatar(config.email); const xml = template.render({ - config: config, - url: url, - icon: icon, - posts: posts, + config, + url, + icon, + posts, feed_url: config.root + feedConfig.path }); diff --git a/rss2.xml b/rss2.xml index d2b1b56..42987d9 100644 --- a/rss2.xml +++ b/rss2.xml @@ -4,7 +4,7 @@ xmlns:content="http://purl.org/rss/1.0/modules/content/"> {{ config.title }} - {{ (url+config.feed.icon) | uriencode }} + {{ icon }} {{ url }} {% if config.feed.hub %}{% endif %} From def618309a4509674fb11b892d5d16fd5dafaa0e Mon Sep 17 00:00:00 2001 From: sehajyang Date: Mon, 4 Nov 2019 09:56:14 +0900 Subject: [PATCH 3/9] Fix : rss2.xml, add image, link tag for icon --- rss2.xml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/rss2.xml b/rss2.xml index 42987d9..b6f382c 100644 --- a/rss2.xml +++ b/rss2.xml @@ -4,8 +4,12 @@ xmlns:content="http://purl.org/rss/1.0/modules/content/"> {{ config.title }} - {{ icon }} {{ url }} + + {{ icon }} + {{ config.title }} + {{ url }} + {% if config.feed.hub %}{% endif %} {{ config.description }} From 8ccffee9498ea5099eb771fbe4881542d058f101 Mon Sep 17 00:00:00 2001 From: sehajyang Date: Mon, 4 Nov 2019 10:15:02 +0900 Subject: [PATCH 4/9] Fix : del encodeURL() that wrapping full_url_for in generator.js --- lib/generator.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/generator.js b/lib/generator.js index 935ba70..2bd0484 100644 --- a/lib/generator.js +++ b/lib/generator.js @@ -35,7 +35,7 @@ module.exports = function(locals) { if (url[url.length - 1] !== '/') url += '/'; let icon = ''; - if (feedConfig.icon) icon = encodeURI(full_url_for.call(this, feedConfig.icon)); + if (feedConfig.icon) icon = full_url_for.call(this, feedConfig.icon); else if (config.email) icon = gravatar(config.email); const xml = template.render({ From f8dde0ccc2526e5e5a9bccc4454f687a07fb28a1 Mon Sep 17 00:00:00 2001 From: curbengh <43627182+curbengh@users.noreply.github.com> Date: Tue, 5 Nov 2019 01:09:10 +0000 Subject: [PATCH 5/9] test(atom): test icon config --- test/index.js | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/test/index.js b/test/index.js index 50da595..ab32666 100644 --- a/test/index.js +++ b/test/index.js @@ -7,7 +7,7 @@ const env = new nunjucks.Environment(); const { join } = require('path'); const { readFileSync } = require('fs'); const cheerio = require('cheerio'); -const { encodeURL } = require('hexo-util'); +const { encodeURL, full_url_for } = require('hexo-util'); env.addFilter('uriencode', str => { return encodeURI(str); @@ -235,6 +235,35 @@ describe('Feed generator', () => { }; checkURL('http://localhost/', '/', 'item:nth-of-type(3)>enclosure'); }); + + it('Icon (atom)', () => { + hexo.config.url = 'http://example.com'; + hexo.config.root = '/'; + + hexo.config.feed = { + type: 'atom', + path: 'atom.xml', + icon: 'icon.svg' + }; + + const result = generator(locals); + const $ = cheerio.load(result.data); + + $('feed>icon').text().should.eql(full_url_for.call(hexo, hexo.config.feed.icon)); + }); + + it('Icon (atom) - no icon', () => { + hexo.config.feed = { + type: 'atom', + path: 'atom.xml', + icon: undefined + }; + + const result = generator(locals); + const $ = cheerio.load(result.data); + + $('feed>icon').length.should.eql(0); + }); }); describe('Autodiscovery', () => { From b58ec71c2d87bb64f8c2e697774b647933b0f5ca Mon Sep 17 00:00:00 2001 From: sehajyang Date: Tue, 5 Nov 2019 10:12:39 +0900 Subject: [PATCH 6/9] Fix : add icon exist check to rss2.xml --- rss2.xml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rss2.xml b/rss2.xml index b6f382c..3a268ba 100644 --- a/rss2.xml +++ b/rss2.xml @@ -5,11 +5,13 @@ {{ config.title }} {{ url }} + {% if icon %} {{ icon }} {{ config.title }} {{ url }} + {% endif %} {% if config.feed.hub %}{% endif %} {{ config.description }} From 07f8b70fa5b0149a5f21450ebcd07a81172770af Mon Sep 17 00:00:00 2001 From: sehajyang Date: Tue, 5 Nov 2019 10:15:27 +0900 Subject: [PATCH 7/9] Fix : atom.xml, added wapper tag for icon --- atom.xml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/atom.xml b/atom.xml index 8b367c5..a97d517 100644 --- a/atom.xml +++ b/atom.xml @@ -1,7 +1,13 @@ {{ config.title }} - {% if icon %}{{ icon }}{% endif %} + {% if icon %} + + {{ icon }} + {{ config.title }} + {{ url }} + + {% endif %} {% if config.subtitle %}{{ config.subtitle }}{% endif %} {% if config.feed.hub %}{% endif %} From e4ea6f662b02332419d0342c479c820fb7c259c8 Mon Sep 17 00:00:00 2001 From: sehajyang Date: Tue, 5 Nov 2019 10:26:55 +0900 Subject: [PATCH 8/9] Revert "Fix : atom.xml, added wapper tag for icon" This reverts commit 07f8b70fa5b0149a5f21450ebcd07a81172770af. --- atom.xml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/atom.xml b/atom.xml index a97d517..8b367c5 100644 --- a/atom.xml +++ b/atom.xml @@ -1,13 +1,7 @@ {{ config.title }} - {% if icon %} - - {{ icon }} - {{ config.title }} - {{ url }} - - {% endif %} + {% if icon %}{{ icon }}{% endif %} {% if config.subtitle %}{{ config.subtitle }}{% endif %} {% if config.feed.hub %}{% endif %} From 417898dc7a5d62b2a5edde73a3c071320b2115bd Mon Sep 17 00:00:00 2001 From: sehajyang Date: Tue, 5 Nov 2019 11:25:50 +0900 Subject: [PATCH 9/9] test(rss2) : test rss2 icon config --- test/index.js | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/index.js b/test/index.js index ab32666..c1ffa8b 100644 --- a/test/index.js +++ b/test/index.js @@ -264,6 +264,35 @@ describe('Feed generator', () => { $('feed>icon').length.should.eql(0); }); + + it('Icon (rss2)', () => { + hexo.config.url = 'http://example.com'; + hexo.config.root = '/'; + + hexo.config.feed = { + type: 'rss2', + path: 'rss2.xml', + icon: 'icon.svg' + }; + + const result = generator(locals); + const $ = cheerio.load(result.data); + + $('rss>channel>image>url').text().should.eql(full_url_for.call(hexo, hexo.config.feed.icon)); + }); + + it('Icon (rss2) - no icon', () => { + hexo.config.feed = { + type: 'rss2', + path: 'rss2.xml', + icon: undefined + }; + + const result = generator(locals); + const $ = cheerio.load(result.data); + + $('rss>channel>image').length.should.eql(0); + }); }); describe('Autodiscovery', () => {