mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-03-11 02:12:21 -05:00
Merge pull request #5108 from ErisDS/rss-2
Add media:content support to RSS
This commit is contained in:
commit
8f5960e1c5
3 changed files with 38 additions and 17 deletions
|
@ -505,7 +505,8 @@ frontendControllers = {
|
||||||
site_url: siteUrl,
|
site_url: siteUrl,
|
||||||
ttl: '60',
|
ttl: '60',
|
||||||
custom_namespaces: {
|
custom_namespaces: {
|
||||||
content: 'http://purl.org/rss/1.0/modules/content/'
|
content: 'http://purl.org/rss/1.0/modules/content/',
|
||||||
|
media: 'http://search.yahoo.com/mrss/'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -525,14 +526,11 @@ frontendControllers = {
|
||||||
url: config.urlFor('post', {post: post, permalinks: permalinks}, true),
|
url: config.urlFor('post', {post: post, permalinks: permalinks}, true),
|
||||||
date: post.published_at,
|
date: post.published_at,
|
||||||
categories: _.pluck(post.tags, 'name'),
|
categories: _.pluck(post.tags, 'name'),
|
||||||
author: post.author ? post.author.name : null
|
author: post.author ? post.author.name : null,
|
||||||
|
custom_elements: []
|
||||||
},
|
},
|
||||||
htmlContent = cheerio.load(post.html, {decodeEntities: false});
|
htmlContent = cheerio.load(post.html, {decodeEntities: false}),
|
||||||
|
image;
|
||||||
if (post.image) {
|
|
||||||
htmlContent('p').first().before('<img src="' + post.image + '" />');
|
|
||||||
htmlContent('img').attr('alt', post.title);
|
|
||||||
}
|
|
||||||
|
|
||||||
// convert relative resource urls to absolute
|
// convert relative resource urls to absolute
|
||||||
['href', 'src'].forEach(function (attributeName) {
|
['href', 'src'].forEach(function (attributeName) {
|
||||||
|
@ -577,13 +575,31 @@ frontendControllers = {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
item.custom_elements = [{
|
item.description = post.meta_description || downsize(htmlContent.html(), {words: 50});
|
||||||
|
|
||||||
|
if (post.image) {
|
||||||
|
image = config.urlFor('image', {image: post.image}, true);
|
||||||
|
|
||||||
|
// Add a media content tag
|
||||||
|
item.custom_elements.push({
|
||||||
|
'media:content': {
|
||||||
|
_attr: {
|
||||||
|
url: image,
|
||||||
|
medium: 'image'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Also add the image to the content, because not all readers support media:content
|
||||||
|
htmlContent('p').first().before('<img src="' + image + '" />');
|
||||||
|
htmlContent('img').attr('alt', post.title);
|
||||||
|
}
|
||||||
|
|
||||||
|
item.custom_elements.push({
|
||||||
'content:encoded': {
|
'content:encoded': {
|
||||||
_cdata: htmlContent.html()
|
_cdata: htmlContent.html()
|
||||||
}
|
}
|
||||||
}];
|
});
|
||||||
|
|
||||||
item.description = post.meta_description || downsize(htmlContent.html(), {words: 50});
|
|
||||||
|
|
||||||
feed.item(item);
|
feed.item(item);
|
||||||
});
|
});
|
||||||
|
|
|
@ -443,7 +443,14 @@ describe('Frontend Routing', function () {
|
||||||
}).catch(done);
|
}).catch(done);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should use meta_description where available', function (done) {
|
it('should use meta_description and image where available', function (done) {
|
||||||
|
var post1End = 'you think :)</p>]]></content:encoded>',
|
||||||
|
post3Title = '<title><![CDATA[Short and Sweet]]>',
|
||||||
|
post3DescStart = '<description><![CDATA[test stuff',
|
||||||
|
post3ContentStart = '<content:encoded><![CDATA[<h2 id=\"testing\">testing</h2>\n\n' +
|
||||||
|
'<img src=\"http:\/\/placekitten.com\/500\/200\"',
|
||||||
|
post3Image = '<media:content url=\"http:\/\/placekitten.com\/500\/200\" medium=\"image\"\/>';
|
||||||
|
|
||||||
request.get('/rss/')
|
request.get('/rss/')
|
||||||
.expect('Content-Type', 'text/xml; charset=utf-8')
|
.expect('Content-Type', 'text/xml; charset=utf-8')
|
||||||
.expect('Cache-Control', testUtils.cacheRules['public'])
|
.expect('Cache-Control', testUtils.cacheRules['public'])
|
||||||
|
@ -454,10 +461,6 @@ describe('Frontend Routing', function () {
|
||||||
}
|
}
|
||||||
|
|
||||||
var content = res.text,
|
var content = res.text,
|
||||||
post1End = 'you think :)</p>]]></content:encoded>',
|
|
||||||
post3Title = '<title><![CDATA[Short and Sweet\]\]>',
|
|
||||||
post3DescStart = '<description><![CDATA[test stuff',
|
|
||||||
post3ContentStart = '<content:encoded><![CDATA[<h2 id=\"testing\">testing</h2>',
|
|
||||||
endIndex = content.indexOf(post1End);
|
endIndex = content.indexOf(post1End);
|
||||||
|
|
||||||
content.indexOf('<rss').should.be.above(0);
|
content.indexOf('<rss').should.be.above(0);
|
||||||
|
@ -465,6 +468,7 @@ describe('Frontend Routing', function () {
|
||||||
content.indexOf(post3Title).should.be.above(endIndex);
|
content.indexOf(post3Title).should.be.above(endIndex);
|
||||||
content.indexOf(post3DescStart).should.be.above(endIndex);
|
content.indexOf(post3DescStart).should.be.above(endIndex);
|
||||||
content.indexOf(post3ContentStart).should.be.above(endIndex);
|
content.indexOf(post3ContentStart).should.be.above(endIndex);
|
||||||
|
content.indexOf(post3Image).should.be.above(endIndex);
|
||||||
content.indexOf('</rss>').should.be.above(0);
|
content.indexOf('</rss>').should.be.above(0);
|
||||||
|
|
||||||
done();
|
done();
|
||||||
|
|
|
@ -23,6 +23,7 @@ DataGenerator.Content = {
|
||||||
slug: "short-and-sweet",
|
slug: "short-and-sweet",
|
||||||
markdown: "## testing\n\nmctesters\n\n- test\n- line\n- items",
|
markdown: "## testing\n\nmctesters\n\n- test\n- line\n- items",
|
||||||
html: "<h2 id=\"testing\">testing</h2>\n\n<p>mctesters</p>\n\n<ul>\n<li>test</li>\n<li>line</li>\n<li>items</li>\n</ul>",
|
html: "<h2 id=\"testing\">testing</h2>\n\n<p>mctesters</p>\n\n<ul>\n<li>test</li>\n<li>line</li>\n<li>items</li>\n</ul>",
|
||||||
|
image: "http://placekitten.com/500/200",
|
||||||
meta_description: "test stuff",
|
meta_description: "test stuff",
|
||||||
published_at: new Date("2015-01-03")
|
published_at: new Date("2015-01-03")
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Reference in a new issue