Skip to content

Commit

Permalink
[gatsby-plugin-feed] Support nested output directory
Browse files Browse the repository at this point in the history
  • Loading branch information
kkosuge committed Jun 9, 2018
1 parent 9091de8 commit 2ffaa21
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/gatsby-plugin-feed/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"dependencies": {
"babel-runtime": "^6.26.0",
"lodash.merge": "^4.6.0",
"mkdirp": "^0.5.1",
"pify": "^3.0.0",
"rss": "^1.2.2"
},
Expand Down
10 changes: 9 additions & 1 deletion packages/gatsby-plugin-feed/src/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import fs from "fs"
import path from "path"
import RSS from "rss"
import merge from "lodash.merge"
import mkdirp from "mkdirp"
import { defaultOptions, runQuery, writeFile } from "./internals"

const publicPath = `./public`
Expand Down Expand Up @@ -54,7 +56,13 @@ exports.onPostBuild = async ({ graphql }, pluginOptions) => {
const items = serializer(locals)

items.forEach(i => feed.item(i))
await writeFile(path.join(publicPath, f.output), feed.xml())

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

return Promise.resolve()
Expand Down

0 comments on commit 2ffaa21

Please sign in to comment.