mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-23 22:11:09 +03:00
Merge pull request #1785 from markberger/1777-rss-with-dated-permalinks
RSS uses correct links when dated permalinks are enabled
This commit is contained in:
commit
ab0ecf65db
@ -12,6 +12,7 @@ var config = require('../config'),
|
||||
when = require('when'),
|
||||
url = require('url'),
|
||||
filters = require('../../server/filters'),
|
||||
coreHelpers = require('../helpers'),
|
||||
|
||||
frontendControllers;
|
||||
|
||||
@ -132,7 +133,8 @@ frontendControllers = {
|
||||
}
|
||||
|
||||
api.posts.browse({page: pageParam}).then(function (page) {
|
||||
var maxPage = page.pages;
|
||||
var maxPage = page.pages,
|
||||
feedItems = [];
|
||||
|
||||
// A bit of a hack for situations with no content.
|
||||
if (maxPage === 0) {
|
||||
@ -147,30 +149,38 @@ frontendControllers = {
|
||||
|
||||
filters.doFilter('prePostsRender', page.posts).then(function (posts) {
|
||||
posts.forEach(function (post) {
|
||||
var item = {
|
||||
title: _.escape(post.title),
|
||||
guid: post.uuid,
|
||||
url: siteUrl + '/' + post.slug + '/',
|
||||
date: post.published_at,
|
||||
categories: _.pluck(post.tags, 'name')
|
||||
},
|
||||
content = post.html;
|
||||
var deferred = when.defer();
|
||||
post.url = coreHelpers.url;
|
||||
post.url().then(function (postUrl) {
|
||||
var item = {
|
||||
title: _.escape(post.title),
|
||||
guid: post.uuid,
|
||||
url: siteUrl + postUrl,
|
||||
date: post.published_at,
|
||||
categories: _.pluck(post.tags, 'name')
|
||||
},
|
||||
content = post.html;
|
||||
|
||||
//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 + "' ";
|
||||
//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 + "' ";
|
||||
});
|
||||
//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;
|
||||
feed.item(item);
|
||||
deferred.resolve();
|
||||
});
|
||||
//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;
|
||||
feed.item(item);
|
||||
feedItems.push(deferred.promise);
|
||||
});
|
||||
});
|
||||
when.all(feedItems).then(function () {
|
||||
res.set('Content-Type', 'text/xml');
|
||||
res.send(feed.xml());
|
||||
});
|
||||
|
@ -2,10 +2,53 @@
|
||||
* Tests if RSS exists and is working
|
||||
*/
|
||||
/*globals CasperTest, casper */
|
||||
CasperTest.begin('Ensure that RSS is available', 3, function suite(test) {
|
||||
CasperTest.begin('Ensure that RSS is available', 11, function suite(test) {
|
||||
casper.thenOpen(url + 'rss/', function (response) {
|
||||
var content = this.getPageContent(),
|
||||
siteTitle = '<title><![CDATA[Ghost]]></title',
|
||||
siteDescription = '<description><![CDATA[Just a blogging platform.]]></description>',
|
||||
siteUrl = '<link>http://127.0.0.1:2369</link>',
|
||||
postTitle = '<![CDATA[Welcome to Ghost]]>',
|
||||
postStart = '<description><![CDATA[<p>You\'re live!',
|
||||
postEnd = 'you think :)</p>]]></description>',
|
||||
postLink = '<link>http://127.0.0.1:2369/welcome-to-ghost/</link>',
|
||||
postCreator = '<dc:creator><![CDATA[Test User]]>';
|
||||
|
||||
test.assertEqual(response.status, 200, 'Response status should be 200.');
|
||||
test.assert(this.getPageContent().indexOf('<rss') >= 0, 'Feed should contain <rss');
|
||||
test.assert(this.getPageContent().indexOf('</rss>') >= 0, 'Feed should contain </rss>');
|
||||
test.assert(content.indexOf('<rss') >= 0, 'Feed should contain <rss');
|
||||
test.assert(content.indexOf(siteTitle) >= 0, 'Feed should contain blog title.');
|
||||
test.assert(content.indexOf(siteDescription) >= 0, 'Feed should contain blog description.');
|
||||
test.assert(content.indexOf(siteUrl) >= 0, 'Feed should contain link to blog.');
|
||||
test.assert(content.indexOf(postTitle) >= 0, 'Feed should contain welcome post title.');
|
||||
test.assert(content.indexOf(postStart) >= 0, 'Feed should contain start of welcome post content.');
|
||||
test.assert(content.indexOf(postEnd) >= 0, 'Feed should contain end of welcome post content.');
|
||||
test.assert(content.indexOf(postLink) >= 0, 'Feed should have link to the welcome post.');
|
||||
test.assert(content.indexOf(postCreator) >= 0, 'Welcome post should have Test User as the creator.');
|
||||
test.assert(content.indexOf('</rss>') >= 0, 'Feed should contain </rss>');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
CasperTest.begin('Ensures dated permalinks works with RSS', 4, function suite(test) {
|
||||
casper.thenOpen(url + "ghost/settings/", function testTitleAndUrl() {
|
||||
test.assertTitle("Ghost Admin", "Ghost admin has no title");
|
||||
test.assertUrlMatch(/ghost\/settings\/general\/$/, "Ghost doesn't require login this time");
|
||||
});
|
||||
casper.thenClick('#permalinks');
|
||||
casper.thenClick('.button-save');
|
||||
casper.waitFor(function successNotification() {
|
||||
return this.evaluate(function () {
|
||||
return document.querySelectorAll('.js-bb-notification section').length > 0;
|
||||
});
|
||||
});
|
||||
casper.thenOpen(url + 'rss/', function (response) {
|
||||
var content = this.getPageContent(),
|
||||
today = new Date(),
|
||||
dd = ("0" + today.getDate()).slice(-2),
|
||||
mm = ("0" + (today.getMonth() + 1)).slice(-2),
|
||||
yyyy = today.getFullYear(),
|
||||
postLink = '/' + yyyy + '/' + mm + '/' + dd + '/welcome-to-ghost/';
|
||||
|
||||
test.assertEqual(response.status, 200, 'Response status should be 200.');
|
||||
test.assert(content.indexOf(postLink) >= 0, 'Feed should have dated permalink.');
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user