Skip to content
This repository was archived by the owner on Jun 13, 2022. It is now read-only.

Commit

Permalink
chore(core): fix the RSS and Atom feeds generation
Browse files Browse the repository at this point in the history
  • Loading branch information
juliomrqz committed Dec 10, 2018
1 parent a5640c2 commit 732eb10
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 32 deletions.
20 changes: 6 additions & 14 deletions packages/@statusfy/core/client/modules/statusfy/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,11 @@ module.exports = async function Statusfy () {
logger.success('Generated /sitemap.xml')

/* Feeds */
const generateFeeds = async index => {
const lang = index || statusfyOptions.siteConfig.defaultLocale
const feeds = await createFeeds(statusfyOptions.siteConfig, lang)
const postfix = index ? `.${lang}` : ''
for (const locale of statusfyOptions.locales) {
const feeds = await createFeeds(statusfyOptions.siteConfig, locale.code)

const rssPath = path.join(this.options.generate.dir, 'feeds', `incidents${postfix}.xml`)
const atomPath = path.join(this.options.generate.dir, 'feeds', `incidents${postfix}.atom`)
const rssPath = path.join(this.options.generate.dir, 'feeds', `incidents.${locale.code}.xml`)
const atomPath = path.join(this.options.generate.dir, 'feeds', `incidents.${locale.code}.atom`)

// Ensure no feed file exists
await fse.remove(rssPath)
Expand All @@ -124,14 +122,8 @@ module.exports = async function Statusfy () {
await fse.writeFile(rssPath, feeds.rss())
await fse.writeFile(atomPath, feeds.atom())

logger.success(`Generated /feeds/incidents${postfix}.xml`)
logger.success(`Generated /feeds/incidents${postfix}.atom`)
}

await generateFeeds()

for (const locale of statusfyOptions.locales) {
await generateFeeds(locale.code)
logger.success(`Generated /feeds/incidents.${locale.code}.xml`)
logger.success(`Generated /feeds/incidents.${locale.code}.atom`)
}

/* Calendars */
Expand Down
2 changes: 1 addition & 1 deletion packages/@statusfy/core/lib/content/feeds.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const buildFeed = (database, siteConfig, lang, isAtom = false) => {
updated: new Date(),
generator: 'Statusfy',
feedLinks: {
atom: `${baseUrl}/feeds/incidents.${lang}.${isAtom ? 'atom' : 'xml'}`
atom: `${siteConfig.baseUrl}/feeds/incidents.${lang}.${isAtom ? 'atom' : 'xml'}`
}
})

Expand Down
26 changes: 9 additions & 17 deletions packages/@statusfy/core/server/extra/feeds.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,19 @@ const router = Router()

const createFeeds = require('../../lib/content/feeds')

router.get('/feeds/incidents:postfix', async (req, res, next) => {
router.get('/feeds/incidents.:lang.:ext', async (req, res, next) => {
const siteConfig = req.app.get('siteConfig')
const { postfix } = req.params
const { lang, ext } = req.params

try {
const p = /(\.\w+\.)?(atom|xml)/i
const m = p.exec(postfix)
const feeds = await createFeeds(siteConfig, lang)

if (m !== null) {
let lang = m[1] ? m[1].replace(/\./g, '') : siteConfig.defaultLocale
let ext = m[2]

const feeds = await createFeeds(siteConfig, lang)

if (ext === 'xml') {
res.set('Content-Type', 'application/rss+xml')
return res.send(feeds.rss())
} else if (ext === 'atom') {
res.set('Content-Type', 'application/atom+xml')
return res.send(feeds.atom())
}
if (ext === 'xml') {
res.set('Content-Type', 'application/rss+xml')
return res.send(feeds.rss())
} else if (ext === 'atom') {
res.set('Content-Type', 'application/atom+xml')
return res.send(feeds.atom())
} else {
next()
}
Expand Down

0 comments on commit 732eb10

Please sign in to comment.