mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-06 22:40:14 -05:00
Fix URL replacement in RSS feed mucking with content
closes #3983 - removed naive regex implementation - added cheerio to project dependencies - used cheerio to parse RSS content - use attribute getter/setter to replace href/src attribute urls with the resolved version
This commit is contained in:
parent
bd163ada46
commit
98d0954e32
2 changed files with 14 additions and 14 deletions
|
@ -14,6 +14,7 @@ var moment = require('moment'),
|
|||
filters = require('../../server/filters'),
|
||||
template = require('../helpers/template'),
|
||||
errors = require('../errors'),
|
||||
cheerio = require('cheerio'),
|
||||
|
||||
frontendControllers,
|
||||
staticPostPermalink,
|
||||
|
@ -485,23 +486,21 @@ frontendControllers = {
|
|||
categories: _.pluck(post.tags, 'name'),
|
||||
author: post.author ? post.author.name : null
|
||||
},
|
||||
content = post.html;
|
||||
htmlContent = cheerio.load(post.html, { decodeEntities: false });
|
||||
|
||||
//set img src to absolute url
|
||||
content = content.replace(/src=["|'|\s]?([\w\/\?\$\.\+\-;%:@&=,_]+)["|'|\s]?/gi, function (match, p1) {
|
||||
/*jslint unparam:true*/
|
||||
p1 = url.resolve(siteUrl, p1);
|
||||
return "src='" + p1 + "' ";
|
||||
// convert relative resource urls to absolute
|
||||
['href', 'src'].forEach(function (attributeName) {
|
||||
htmlContent('[' + attributeName + ']').each(function (ix, el) {
|
||||
el = htmlContent(el);
|
||||
|
||||
var attributeValue = el.attr(attributeName);
|
||||
attributeValue = url.resolve(siteUrl, attributeValue);
|
||||
|
||||
el.attr(attributeName, attributeValue);
|
||||
});
|
||||
});
|
||||
|
||||
//set a href to absolute url
|
||||
content = content.replace(/href=["|'|\s]?([\w\/\?\$\.\+\-;%:@&=,_]+)["|'|\s]?/gi, function (match, p1) {
|
||||
/*jslint unparam:true*/
|
||||
p1 = url.resolve(siteUrl, p1);
|
||||
return "href='" + p1 + "' ";
|
||||
});
|
||||
|
||||
item.description = content;
|
||||
item.description = htmlContent.html();
|
||||
feed.item(item);
|
||||
});
|
||||
}).then(function () {
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
"body-parser": "1.6.3",
|
||||
"bookshelf": "0.7.6",
|
||||
"busboy": "0.2.3",
|
||||
"cheerio": "0.17.0",
|
||||
"colors": "0.6.2",
|
||||
"compression": "^1.0.2",
|
||||
"connect": "3.0.0-rc.1",
|
||||
|
|
Loading…
Reference in a new issue