From ed5f5adb0827a640feacbe84784d1ff32ab17662 Mon Sep 17 00:00:00 2001 From: Hippo Date: Sun, 29 Sep 2019 17:59:24 +0530 Subject: [PATCH] Change RSS feed back to /rss but using Gatsby not Ghost For future compatibility with Ghost. Trying to make this point to the Gatsby site URL rather than the Ghost one :-/ --- src/components/common/Layout.js | 2 +- src/utils/rss/generate-feed.js | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/components/common/Layout.js b/src/components/common/Layout.js index 037ba31..721c435 100644 --- a/src/components/common/Layout.js +++ b/src/components/common/Layout.js @@ -51,7 +51,7 @@ const DefaultLayout = ({ data, children, bodyClass, isHome, hasFeatureImage }) =
{ site.twitter && Twitter} { site.facebook && Facebook} - RSS Feed + RSS Feed
{ isHome ? diff --git a/src/utils/rss/generate-feed.js b/src/utils/rss/generate-feed.js index 9a06c0b..269a7c7 100644 --- a/src/utils/rss/generate-feed.js +++ b/src/utils/rss/generate-feed.js @@ -2,8 +2,18 @@ const cheerio = require(`cheerio`) const tagsHelper = require(`@tryghost/helpers`).tags const _ = require(`lodash`) -const generateItem = function generateItem(post) { - const itemUrl = post.url +const generateItem = function generateItem(post, siteUrl) { + /* + * TODO: detect URL from post.url + * + * Right now post.url returns the Ghost version of the post, + * hence this hack to show the Gatsby site version. But here + * the URL is regenerated from slug, which may not match the + * actual Ghost config. Ideally, we should take post.url, + * remove the ghost site prefix, and replace that with + * siteUrl. + */ + const itemUrl = siteUrl + '/' + post.slug + '/' const html = post.html const htmlContent = cheerio.load(html, { decodeEntities: false, xmlMode: true }) const item = { @@ -46,7 +56,7 @@ const generateItem = function generateItem(post) { const generateRSSFeed = function generateRSSFeed(siteConfig) { return { - serialize: ({ query: { allGhostPost } }) => allGhostPost.edges.map(edge => Object.assign({}, generateItem(edge.node))), + serialize: ({ query: { allGhostPost } }) => allGhostPost.edges.map(edge => Object.assign({}, generateItem(edge.node, siteConfig.siteUrl))), setup: ({ query: { allGhostSettings } }) => { const siteTitle = allGhostSettings.edges[0].node.title || `No Title` const siteDescription = allGhostSettings.edges[0].node.description || `No Description` @@ -55,7 +65,7 @@ const generateRSSFeed = function generateRSSFeed(siteConfig) { description: siteDescription, // generator: `Ghost ` + data.safeVersion, generator: `Ghost 2.9`, - feed_url: `${siteConfig.siteUrl}/rss/`, + feed_url: `${siteConfig.siteUrl}/rss`, site_url: `${siteConfig.siteUrl}/`, image_url: `${siteConfig.siteUrl}/${siteConfig.siteIcon}`, ttl: `60`, @@ -114,7 +124,7 @@ const generateRSSFeed = function generateRSSFeed(siteConfig) { } } `, - output: `/feed.xml`, + output: `/rss`, } }