Skip to content

Commit

Permalink
Merge pull request #68 from oncletom/patch-1
Browse files Browse the repository at this point in the history
Add image enclosure with post.image metadata
  • Loading branch information
yoshinorin committed Jan 1, 2019
2 parents d02618d + 0cf6d37 commit fec1dac
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
3 changes: 3 additions & 0 deletions atom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
{% endif %}
{% endif %}
</summary>
{% if post.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 }}"/>
{% endfor %}
Expand Down
3 changes: 3 additions & 0 deletions rss2.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
{% endif %}
{% endif %}
</description>
{% if post.image %}
<enclosure url="{{ (url + post.image) | uriencode }}" type="image" />
{% endif %}
{% if config.feed.content and post.content %}
<content:encoded><![CDATA[{{ post.content | noControlChars | safe }}]]></content:encoded>
{% endif %}
Expand Down
36 changes: 31 additions & 5 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('Feed generator', function() {
return Post.insert([
{source: 'foo', slug: 'foo', content: '<h6>TestHTML</h6>', date: 1e8},
{source: 'bar', slug: 'bar', date: 1e8 + 1},
{source: 'baz', slug: 'baz', date: 1e8 - 1}
{source: 'baz', slug: 'baz', title: 'With Image', image: 'test.png', date: 1e8 - 1}
]).then(function(data) {
posts = Post.sort('-date');
locals = hexo.locals.toObject();
Expand All @@ -54,7 +54,7 @@ describe('Feed generator', function() {
hexo.config.feed = {
type: 'atom',
path: 'atom.xml',
limit: 2
limit: 3
};
hexo.config = assign(hexo.config, urlConfig);
var result = generator(locals);
Expand All @@ -63,7 +63,7 @@ describe('Feed generator', function() {
result.data.should.eql(atomTmpl.render({
config: hexo.config,
url: urlConfig.url,
posts: posts.limit(2),
posts: posts.limit(3),
feed_url: hexo.config.root + 'atom.xml'
}));
});
Expand All @@ -72,7 +72,7 @@ describe('Feed generator', function() {
hexo.config.feed = {
type: 'rss2',
path: 'rss2.xml',
limit: 2
limit: 3
};
hexo.config = assign(hexo.config, urlConfig);
var result = generator(locals);
Expand All @@ -81,7 +81,7 @@ describe('Feed generator', function() {
result.data.should.eql(rss2Tmpl.render({
config: hexo.config,
url: urlConfig.url,
posts: posts.limit(2),
posts: posts.limit(3),
feed_url: hexo.config.root + 'rss2.xml'
}));
});
Expand Down Expand Up @@ -165,4 +165,30 @@ describe('Feed generator', function() {

});

it('Prints an enclosure on `image` metadata', function() {
hexo.config.feed = {
type: 'atom',
path: 'atom.xml'
};

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

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

$(selector).length.should.eq(1);
};

checkURL('http://localhost/', '/', 'feed>entry:nth-of-type(3)>content[type="image"]');

hexo.config.feed = {
type: 'rss2',
path: 'rss2.xml',
content: true
};
checkURL('http://localhost/', '/', 'item:nth-of-type(3)>enclosure');
});

});

0 comments on commit fec1dac

Please sign in to comment.