Skip to content

Commit

Permalink
add warn
Browse files Browse the repository at this point in the history
  • Loading branch information
Laurie committed Feb 10, 2021
1 parent 82cf4f8 commit 219c1a8
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions packages/gatsby-plugin-feed/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const publicPath = `./public`

exports.pluginOptionsSchema = pluginOptionsSchema

exports.onPostBuild = async ({ graphql }, pluginOptions) => {
exports.onPostBuild = async ({ graphql }, pluginOptions, reporter) => {
/*
* Run the site settings query to gather context, then
* then run the corresponding feed for each query.
Expand All @@ -34,16 +34,22 @@ exports.onPostBuild = async ({ graphql }, pluginOptions) => {
...feed,
}

const rssFeed = (await feed.serialize(locals)).reduce((merged, item) => {
merged.item(item)
return merged
}, new RSS(setup(locals)))

const outputPath = path.join(publicPath, feed.output)
const outputDir = path.dirname(outputPath)
if (!(await fs.exists(outputDir))) {
await fs.mkdirp(outputDir)
if (!feed.serialize || typeof feed.serialize !== `function`) {
reporter.warn(
`You did not pass in a valid serialize function. Your feed will not be generated.`
)
} else {
const rssFeed = (await feed.serialize(locals)).reduce((merged, item) => {
merged.item(item)
return merged
}, new RSS(setup(locals)))

const outputPath = path.join(publicPath, feed.output)
const outputDir = path.dirname(outputPath)
if (!(await fs.exists(outputDir))) {
await fs.mkdirp(outputDir)
}
await fs.writeFile(outputPath, rssFeed.xml())
}
await fs.writeFile(outputPath, rssFeed.xml())
}
}

0 comments on commit 219c1a8

Please sign in to comment.