diff --git a/core/server/controllers/frontend.js b/core/server/controllers/frontend.js index 83f3501ba6..44f8cfc82e 100644 --- a/core/server/controllers/frontend.js +++ b/core/server/controllers/frontend.js @@ -15,6 +15,7 @@ var moment = require('moment'), template = require('../helpers/template'), errors = require('../errors'), cheerio = require('cheerio'), + downsize = require('downsize'), routeMatch = require('path-match')(), frontendControllers, @@ -500,7 +501,10 @@ frontendControllers = { generator: 'Ghost ' + trimmedVersion, feed_url: feedUrl, site_url: siteUrl, - ttl: '60' + ttl: '60', + custom_namespaces: { + content: 'http://purl.org/rss/1.0/modules/content/' + } }); // If page is greater than number of pages we have, redirect to last page @@ -566,11 +570,18 @@ frontendControllers = { }); }); - item.description = htmlContent.html(); + item.custom_elements = [{ + 'content:encoded': { + _cdata: htmlContent.html() + } + }]; + + item.description = post.meta_description || downsize(htmlContent.html(), {words: 50}); + feed.item(item); }); }).then(function () { - res.set('Content-Type', 'application/rss+xml; charset=UTF-8'); + res.set('Content-Type', 'text/xml; charset=UTF-8'); res.send(feed.xml()); }); }); diff --git a/core/test/functional/routes/frontend_test.js b/core/test/functional/routes/frontend_test.js index 5f91509018..dedd9aedb2 100644 --- a/core/test/functional/routes/frontend_test.js +++ b/core/test/functional/routes/frontend_test.js @@ -376,7 +376,7 @@ describe('Frontend Routing', function () { it('should respond with xml', function (done) { request.get('/rss/') - .expect('Content-Type', 'application/rss+xml; charset=utf-8') + .expect('Content-Type', 'text/xml; charset=utf-8') .expect('Cache-Control', testUtils.cacheRules['public']) .expect(200) .end(function (err, res) { @@ -394,8 +394,9 @@ describe('Frontend Routing', function () { siteDescription = '', siteUrl = 'http://127.0.0.1:2369/', postTitle = '', - postStart = 'You\'re live!', - postEnd = 'you think :)

]]>
', + descStart = 'You\'re live!', + postStart = 'You\'re live!', + postEnd = 'you think :)

]]>
', postLink = 'http://127.0.0.1:2369/welcome-to-ghost/', postCreator = '', author = ''; @@ -405,6 +406,7 @@ describe('Frontend Routing', function () { content.indexOf(siteDescription).should.be.above(0); content.indexOf(siteUrl).should.be.above(0); content.indexOf(postTitle).should.be.above(0); + content.indexOf(descStart).should.be.above(0); content.indexOf(postStart).should.be.above(0); content.indexOf(postEnd).should.be.above(0); content.indexOf(postLink).should.be.above(0); @@ -434,11 +436,45 @@ describe('Frontend Routing', function () { .end(doEnd(done)); }); - describe('RSS pages', function () { + describe('More RSS', function () { before(function (done) { testUtils.fixtures.insertPosts().then(function () { - return testUtils.fixtures.insertMorePosts(11); - }).then(function () { + done(); + }).catch(done); + }); + + it('should use meta_description where available', function (done) { + request.get('/rss/') + .expect('Content-Type', 'text/xml; charset=utf-8') + .expect('Cache-Control', testUtils.cacheRules['public']) + .expect(200) + .end(function (err, res) { + if (err) { + return done(err); + } + + var content = res.text, + post1End = 'you think :)

]]>', + post3Title = '<![CDATA[Short and Sweet\]\]>', + post3DescStart = '<description><![CDATA[test stuff', + post3ContentStart = '<content:encoded><![CDATA[<h2 id=\"testing\">testing</h2>', + endIndex = content.indexOf(post1End); + + content.indexOf('<rss').should.be.above(0); + content.indexOf(post1End).should.be.above(0); + content.indexOf(post3Title).should.be.above(endIndex); + content.indexOf(post3DescStart).should.be.above(endIndex); + content.indexOf(post3ContentStart).should.be.above(endIndex); + content.indexOf('</rss>').should.be.above(0); + + done(); + }); + }); + }); + + describe('RSS pages', function () { + before(function (done) { + testUtils.fixtures.insertMorePosts(11).then(function () { done(); }).catch(done); }); @@ -899,7 +935,7 @@ describe('Frontend Routing', function () { it('should serve RSS with date permalink', function (done) { request.get('/rss/') - .expect('Content-Type', 'application/rss+xml; charset=utf-8') + .expect('Content-Type', 'text/xml; charset=utf-8') .expect('Cache-Control', testUtils.cacheRules['public']) .expect(200) .end(function (err, res) { diff --git a/core/test/utils/fixtures/data-generator.js b/core/test/utils/fixtures/data-generator.js index 652187d1c7..3ff05dfec3 100644 --- a/core/test/utils/fixtures/data-generator.js +++ b/core/test/utils/fixtures/data-generator.js @@ -23,6 +23,7 @@ DataGenerator.Content = { slug: "short-and-sweet", 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>", + meta_description: "test stuff", published_at: new Date("2015-01-03") }, { diff --git a/package.json b/package.json index a0e6896b54..ee664f570a 100644 --- a/package.json +++ b/package.json @@ -60,13 +60,13 @@ "passport-oauth2-client-password": "0.1.2", "path-match": "1.2.2", "request": "2.51.0", - "rss": "1.0.0", + "rss": "1.1.1", "semver": "4.1.0", "showdown-ghost": "0.3.6", "sqlite3": "3.0.5", "unidecode": "0.1.3", "validator": "3.28.0", - "xml": "0.0.12" + "xml": "1.0.0" }, "optionalDependencies": { "mysql": "2.1.1",