Skip to content

Commit

Permalink
Merge pull request #57 from styxlab/fix-rss
Browse files Browse the repository at this point in the history
Fix rss
  • Loading branch information
styxlab authored Mar 3, 2021
2 parents 5347ef4 + 87f81e4 commit 3d310fa
Show file tree
Hide file tree
Showing 4 changed files with 408 additions and 503 deletions.
30 changes: 15 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"postbuild": "next-sitemap"
},
"dependencies": {
"@tryghost/content-api": "^1.4.13",
"@tryghost/content-api": "^1.4.15",
"@types/refractor": "^3.0.0",
"cheerio": "^1.0.0-rc.5",
"dayjs": "^1.10.4",
Expand All @@ -48,8 +48,8 @@
"fs": "^0.0.1-security",
"hast-util-to-string": "^1.0.4",
"lodash.throttle": "^4.1.1",
"next": "^10.0.6",
"nodemailer": "^6.4.17",
"next": "^10.0.7",
"nodemailer": "^6.5.0",
"nodemailer-smtp-transport": "^2.7.4",
"probe-image-size": "^6.0.0",
"react": "17.0.1",
Expand All @@ -63,32 +63,32 @@
"unist-util-visit": "^2.0.3"
},
"devDependencies": {
"@next/bundle-analyzer": "^10.0.6",
"@types/cheerio": "^0.22.23",
"@next/bundle-analyzer": "^10.0.7",
"@types/cheerio": "^0.22.24",
"@types/lodash": "^4.14.168",
"@types/node": "^14.14.22",
"@types/node": "^14.14.31",
"@types/nodemailer": "^6.4.0",
"@types/nodemailer-smtp-transport": "^2.7.4",
"@types/react": "^17.0.1",
"@types/react": "^17.0.2",
"@types/rss": "^0.0.28",
"@types/sanitize-html": "^1.27.1",
"@types/styled-components": "^5.1.7",
"@types/testing-library__react": "^10.2.0",
"@types/tryghost__content-api": "^1.3.6",
"@typescript-eslint/eslint-plugin": "^4.14.2",
"@typescript-eslint/parser": "^4.14.2",
"@typescript-eslint/eslint-plugin": "^4.16.1",
"@typescript-eslint/parser": "^4.16.1",
"autoprefixer": "^10.2.4",
"critters": "^0.0.6",
"eslint": "^7.19.0",
"eslint-config-prettier": "^7.2.0",
"critters": "^0.0.7",
"eslint": "^7.21.0",
"eslint-config-prettier": "^8.1.0",
"eslint-plugin-react": "^7.22.0",
"eslint-plugin-react-hooks": "^4.2.0",
"next-sitemap": "^1.4.17",
"postcss": "^8.2.4",
"next-sitemap": "^1.5.10",
"postcss": "^8.2.6",
"postcss-color-mod-function": "^3.0.3",
"postcss-easy-import": "^3.0.0",
"postcss-preset-env": "^6.7.0",
"prettier": "^2.2.1",
"typescript": "^4.1.3"
"typescript": "^4.2.2"
}
}
9 changes: 1 addition & 8 deletions pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { GetStaticProps, GetStaticPropsContext } from 'next'
import { GetStaticProps } from 'next'
import { useRouter } from 'next/router'
import fs from 'fs'

import { Layout } from '@components/Layout'
import { PostView } from '@components/PostView'
Expand All @@ -11,7 +10,6 @@ import { SEO } from '@meta/seo'
import { processEnv } from '@lib/processEnv'
import { getAllPosts, getAllSettings, GhostPostOrPage, GhostPostsOrPages, GhostSettings } from '@lib/ghost'
import { seoImage, ISeoImage } from '@meta/seoImage'
import { generateRSSFeed } from '@utils/rss'

import { BodyClass } from '@helpers/BodyClass'

Expand Down Expand Up @@ -69,11 +67,6 @@ export const getStaticProps: GetStaticProps = async () => {
throw new Error('Index creation failed.')
}

if (settings.processEnv.rssFeed) {
const rss = generateRSSFeed({ posts, settings })
fs.writeFileSync('./public/rss.xml', rss)
}

const cmsData = {
settings,
posts,
Expand Down
35 changes: 35 additions & 0 deletions pages/rss.xml.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { GetServerSideProps } from 'next'

import { getAllPosts, getAllSettings, GhostPostsOrPages } from '@lib/ghost'
import { generateRSSFeed } from '@utils/rss'

const RSS = () => null

export const getServerSideProps: GetServerSideProps = async ({ res }) => {
let settings
let posts: GhostPostsOrPages | []

try {
settings = await getAllSettings()
posts = await getAllPosts()
} catch (error) {
throw new Error('Index creation failed.')
}

let rssData = null
if (settings.processEnv.rssFeed) {
rssData = generateRSSFeed({ posts, settings })
}

if (res && rssData) {
res.setHeader('Content-Type', 'text/xml')
res.write(rssData)
res.end()
}

return {
props: {},
}
}

export default RSS
Loading

1 comment on commit 3d310fa

@vercel
Copy link

@vercel vercel bot commented on 3d310fa Mar 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.