diff --git a/atom.xml b/atom.xml index 36f16d4..8b367c5 100644 --- a/atom.xml +++ b/atom.xml @@ -1,25 +1,25 @@ - + {{ config.title }} {% if icon %}{{ icon }}{% endif %} {% if config.subtitle %}{{ config.subtitle }}{% endif %} {% if config.feed.hub %}{% endif %} - + {{ posts.first().updated.toISOString() }} - {{ url }} + {{ url | uriencode }} {% if config.author %} {{ config.author }} {% if config.email %}{{ config.email }}{% endif %} {% endif %} - Hexo + Hexo {% for post in posts.toArray() %} {{ post.title }} - - {{ url }}{{ post.path }} + + {{ post.permalink | uriencode }} {{ post.date.toISOString() }} {{ post.updated.toISOString() }} {% if config.feed.content and post.content %} @@ -47,13 +47,13 @@ {% endif %} {% if post.image %} - + {% endif %} {% for category in post.categories.toArray() %} - + {% endfor %} {% for tag in post.tags.toArray() %} - + {% endfor %} {% endfor %} diff --git a/lib/generator.js b/lib/generator.js index 00b595c..33b2e1e 100644 --- a/lib/generator.js +++ b/lib/generator.js @@ -4,10 +4,10 @@ const nunjucks = require('nunjucks'); const env = new nunjucks.Environment(); const { join } = require('path'); const { readFileSync } = require('fs'); -const { gravatar } = require('hexo-util'); +const { encodeURL, gravatar } = require('hexo-util'); env.addFilter('uriencode', str => { - return encodeURI(str); + return encodeURL(str); }); env.addFilter('noControlChars', str => { diff --git a/rss2.xml b/rss2.xml index 927bba7..3fe7ac4 100644 --- a/rss2.xml +++ b/rss2.xml @@ -13,8 +13,8 @@ {% for post in posts.toArray() %} {{ post.title }} - {{ url }}{{ post.path | uriencode }} - {{ url }}{{ post.path | uriencode }} + {{ post.permalink | uriencode }} + {{ post.permalink | uriencode }} {{ post.date.toDate().toUTCString() }} {% if post.description %} @@ -38,12 +38,12 @@ {% endif %} {% if post.image %} - + {% endif %} {% if config.feed.content and post.content %} {% endif %} - {% if post.comments %}{{ url }}{{ post.path | uriencode }}#disqus_thread{% endif %} + {% if post.comments %}{{ post.permalink | uriencode }}#disqus_thread{% endif %} {% endfor %} diff --git a/test/index.js b/test/index.js index 5c79ac9..d6f3768 100644 --- a/test/index.js +++ b/test/index.js @@ -7,6 +7,7 @@ const env = new nunjucks.Environment(); const { join } = require('path'); const { readFileSync } = require('fs'); const cheerio = require('cheerio'); +const { encodeURL } = require('hexo-util'); env.addFilter('uriencode', str => { return encodeURI(str); @@ -148,7 +149,6 @@ describe('Feed generator', () => { const $ = cheerio.load(result.data); $('feed>id').text().should.eql(valid); - $('feed>entry>link').attr('href').should.eql(valid); }; checkURL('http://localhost/', '/', 'http://localhost/'); @@ -170,20 +170,21 @@ describe('Feed generator', () => { path: 'atom.xml' }; - const checkURL = function(url, root, valid) { + const checkURL = function(url, root) { hexo.config.url = url; hexo.config.root = root; const result = generator(locals); const $ = cheerio.load(result.data); - $('feed>id').text().should.eql(valid); - $('feed>entry>link').attr('href').should.eql(valid); + if (url[url.length - 1] !== '/') url += '/'; + const punyIDN = encodeURL(url); + $('feed>id').text().should.eql(punyIDN); }; - const IDN = 'http://gôg.com/'; - checkURL(IDN, '/', IDN); - checkURL(IDN, 'blo g/', IDN); + checkURL('http://gôg.com/', '/'); + + checkURL('http://gôg.com/bár', '/bár/'); }); it('Root encoding', () => {