Skip to content

Commit

Permalink
Merge d4693ce into 0c26cbd
Browse files Browse the repository at this point in the history
  • Loading branch information
tomap committed Jul 9, 2019
2 parents 0c26cbd + d4693ce commit ce194f8
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 13 deletions.
12 changes: 6 additions & 6 deletions atom.xml
Expand Up @@ -5,7 +5,7 @@
{% if config.subtitle %}<subtitle>{{ config.subtitle }}</subtitle>{% endif %}
<link href="{{ feed_url | uriencode }}" rel="self"/>
{% if config.feed.hub %}<link href="{{ config.feed.hub | uriencode }}" rel="hub"/>{% endif %}
<link href="{{ url | uriencode }}"/>
<link href="{{ url }}"/>
<updated>{{ posts.first().updated.toISOString() }}</updated>
<id>{{ url }}</id>
{% if config.author %}
Expand All @@ -18,8 +18,8 @@
{% for post in posts.toArray() %}
<entry>
<title>{{ post.title }}</title>
<link href="{{ (url + post.path) | uriencode }}"/>
<id>{{ url + post.path }}</id>
<link href="{{ url }}{{ post.path | uriencode }}"/>
<id>{{ url }}{{ post.path }}</id>
<published>{{ post.date.toISOString() }}</published>
<updated>{{ post.updated.toISOString() }}</updated>
{% if config.feed.content and post.content %}
Expand Down Expand Up @@ -47,13 +47,13 @@
{% endif %}
</summary>
{% if post.image %}
<content src="{{ (url + post.image) | uriencode }}" type="image" />
<content src="{{ url }}{{ post.image | uriencode }}" type="image" />
{% endif %}
{% for category in post.categories.toArray() %}
<category term="{{ category.name }}" scheme="{{ (url + category.path) | uriencode }}"/>
<category term="{{ category.name }}" scheme="{{ url }}{{ category.path | uriencode }}"/>
{% endfor %}
{% for tag in post.tags.toArray() %}
<category term="{{ tag.name }}" scheme="{{ (url + tag.path) | uriencode }}"/>
<category term="{{ tag.name }}" scheme="{{ url }}{{ tag.path | uriencode }}"/>
{% endfor %}
</entry>
{% endfor %}
Expand Down
2 changes: 1 addition & 1 deletion lib/generator.js
Expand Up @@ -35,7 +35,7 @@ module.exports = function(locals) {
if (url[url.length - 1] !== '/') url += '/';

var icon;
if (feedConfig.icon) icon = url + feedConfig.icon;
if (feedConfig.icon) icon = url + encodeURI(feedConfig.icon);
else if (config.email) icon = gravatar(config.email);

var xml = template.render({
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -29,7 +29,7 @@
"author": "Tommy Chen <tommy351@gmail.com> (http://zespia.tw)",
"maintainers": [
"Abner Chou <hi@abnerchou.me> (http://abnerchou.me)"
],
],
"license": "MIT",
"dependencies": {
"nunjucks": "^3.0.0"
Expand Down
10 changes: 5 additions & 5 deletions rss2.xml
Expand Up @@ -4,7 +4,7 @@
xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
<title>{{ config.title }}</title>
<link>{{ url | uriencode }}</link>
<link>{{ url }}</link>
<atom:link href="{{ feed_url | uriencode }}" rel="self" type="application/rss+xml"/>
{% if config.feed.hub %}<atom:link href="{{ config.feed.hub | uriencode }}" rel="hub"/>{% endif %}
<description>{{ config.description }}</description>
Expand All @@ -13,8 +13,8 @@
{% for post in posts.toArray() %}
<item>
<title>{{ post.title }}</title>
<link>{{ (url + post.path) | uriencode }}</link>
<guid>{{ (url + post.path) | uriencode }}</guid>
<link>{{ url }}{{ post.path | uriencode }}</link>
<guid>{{ url }}{{ post.path | uriencode }}</guid>
<pubDate>{{ post.date.toDate().toUTCString() }}</pubDate>
<description>
{% if post.description %}
Expand All @@ -38,12 +38,12 @@
{% endif %}
</description>
{% if post.image %}
<enclosure url="{{ (url + post.image) | uriencode }}" type="image" />
<enclosure url="{{ url + post.image }}" type="image" />
{% endif %}
{% if config.feed.content and post.content %}
<content:encoded><![CDATA[{{ post.content | noControlChars | safe }}]]></content:encoded>
{% endif %}
{% if post.comments %}<comments>{{ (url + post.path) | uriencode }}#disqus_thread</comments>{% endif %}
{% if post.comments %}<comments>{{ url }}{{ post.path | uriencode }}#disqus_thread</comments>{% endif %}
</item>
{% endfor %}
</channel>
Expand Down
45 changes: 45 additions & 0 deletions test/index.js
Expand Up @@ -164,6 +164,51 @@ describe('Feed generator', function() {

});

it('IDN handling', function() {
hexo.config.feed = {
type: 'atom',
path: 'atom.xml'
};

var checkURL = function(url, root, valid) {
hexo.config.url = url;
hexo.config.root = root;

var result = generator(locals);
var $ = cheerio.load(result.data);

$('feed>id').text().should.eql(valid);
$('feed>entry>link').attr('href').should.eql(valid);
};
var IDN = 'http://gôg.com/';
checkURL(IDN, '/', IDN);

checkURL(IDN, 'blo g/', IDN);
});

it('Root encoding', function() {
var file = 'atom.xml';
hexo.config.feed = {
type: 'atom',
path: file
};

var domain = 'http://example.com/';

var checkURL = function(root, valid) {
hexo.config.url = domain;
hexo.config.root = root;

var result = generator(locals);
var $ = cheerio.load(result.data);

$('feed>link').attr('href').should.eql(valid);
};
checkURL('/', '/' + file);

checkURL('blo g/', 'blo%20g/' + file);
});

it('Prints an enclosure on `image` metadata', function() {
hexo.config.feed = {
type: 'atom',
Expand Down

0 comments on commit ce194f8

Please sign in to comment.