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 :-/
This commit is contained in:
parent
0b24fb79eb
commit
ed5f5adb08
2 changed files with 16 additions and 6 deletions
|
@ -51,7 +51,7 @@ const DefaultLayout = ({ data, children, bodyClass, isHome, hasFeatureImage }) =
|
|||
<div className="site-mast-right">
|
||||
{ site.twitter && <a href={ twitterUrl } className="site-nav-item" target="_blank" rel="noopener noreferrer"><img className="site-nav-icon" src="/images/icons/twitter.svg" alt="Twitter" /></a>}
|
||||
{ site.facebook && <a href={ facebookUrl } className="site-nav-item" target="_blank" rel="noopener noreferrer"><img className="site-nav-icon" src="/images/icons/facebook.svg" alt="Facebook" /></a>}
|
||||
<a className="site-nav-item" href={ `https://feedly.com/i/subscription/feed/${config.siteUrl}/feed.xml` } target="_blank" rel="noopener noreferrer"><img className="site-nav-icon" src="/images/icons/rss.svg" alt="RSS Feed" /></a>
|
||||
<a className="site-nav-item" href={ `https://feedly.com/i/subscription/feed/${config.siteUrl}/rss` } target="_blank" rel="noopener noreferrer"><img className="site-nav-icon" src="/images/icons/rss.svg" alt="RSS Feed" /></a>
|
||||
</div>
|
||||
</div>
|
||||
{ isHome ?
|
||||
|
|
|
@ -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`,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue