diff --git a/packages/gatsby-plugin-feed/src/__tests__/__snapshots__/gatsby-node.js.snap b/packages/gatsby-plugin-feed/src/__tests__/__snapshots__/gatsby-node.js.snap
index 4fc93c5b58083..8afcfcd91b060 100644
--- a/packages/gatsby-plugin-feed/src/__tests__/__snapshots__/gatsby-node.js.snap
+++ b/packages/gatsby-plugin-feed/src/__tests__/__snapshots__/gatsby-node.js.snap
@@ -1,9 +1,13 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
-exports[`Test plugin feed custom query runs 1`] = `"http://github.com/dylang/node-rssRSS for NodeMon, 01 Jan 2018 00:00:00 GMT- http://dummy.url/a-custom-pathhttp://dummy.url/a-custom-path
- http://dummy.url/another-custom-pathhttp://dummy.url/another-custom-path
"`;
+exports[`Test plugin feed custom properties work properly 1`] = `"http://github.com/dylang/node-rsscustom generatorMon, 01 Jan 2018 00:00:00 GMT- http://dummy.url/a-custom-pathhttp://dummy.url/a-custom-path
- http://dummy.url/another-custom-pathhttp://dummy.url/another-custom-path
"`;
-exports[`Test plugin feed default settings work properly 1`] = `"http://github.com/dylang/node-rssRSS for NodeMon, 01 Jan 2018 00:00:00 GMT- http://dummy.url/a-slughttp://dummy.url/a-slug
"`;
+exports[`Test plugin feed custom query runs 1`] = `"http://github.com/dylang/node-rssGatsbyJSMon, 01 Jan 2018 00:00:00 GMT- http://dummy.url/a-custom-pathhttp://dummy.url/a-custom-path
- http://dummy.url/another-custom-pathhttp://dummy.url/another-custom-path
"`;
+
+exports[`Test plugin feed default settings work properly 1`] = `"http://github.com/dylang/node-rssGatsbyJSMon, 01 Jan 2018 00:00:00 GMT- http://dummy.url/a-slughttp://dummy.url/a-slug
"`;
exports[`Test plugin feed options validation throws when invalid plugin options 1`] = `[Error: [Config Validation]: "output" is required]`;
exports[`Test plugin feed options validation throws when invalid plugin options 2`] = `[Error: [Config Validation]: "query" is required]`;
+
+exports[`Test plugin feed options validation throws when invalid plugin options 3`] = `[Error: [Config Validation]: "title" is required]`;
diff --git a/packages/gatsby-plugin-feed/src/__tests__/gatsby-node.js b/packages/gatsby-plugin-feed/src/__tests__/gatsby-node.js
index 2d79eab4937c4..eca07d1538d8c 100644
--- a/packages/gatsby-plugin-feed/src/__tests__/gatsby-node.js
+++ b/packages/gatsby-plugin-feed/src/__tests__/gatsby-node.js
@@ -53,6 +53,7 @@ describe(`Test plugin feed`, async () => {
{
output: `rss.xml`,
query: `{}`,
+ title: `my feed`,
},
],
}
@@ -72,6 +73,7 @@ describe(`Test plugin feed`, async () => {
{
// output is missing
query: `{}`,
+ title: `my feed`,
},
],
},
@@ -79,7 +81,17 @@ describe(`Test plugin feed`, async () => {
feeds: [
{
output: `rss.xml`,
- // query is misisng
+ // query is missing
+ title: `my feed`,
+ },
+ ],
+ },
+ {
+ feeds: [
+ {
+ output: `rss.xml`,
+ query: `{}`,
+ // title is missing
},
],
},
@@ -130,6 +142,82 @@ describe(`Test plugin feed`, async () => {
expect(contents).toMatchSnapshot()
})
+ it(`custom properties work properly`, async () => {
+ fs.writeFile = jest.fn()
+ fs.writeFile.mockResolvedValue(true)
+ const graphql = jest.fn()
+ graphql.mockResolvedValue({
+ data: {
+ site: {
+ siteMetadata: {
+ title: `site title`,
+ description: `a description`,
+ siteUrl: `http://dummy.url/`,
+ },
+ },
+ allMarkdownRemark: {
+ edges: [
+ {
+ node: {
+ frontmatter: {
+ path: `a-custom-path`,
+ },
+ excerpt: `post description`,
+ },
+ },
+ {
+ node: {
+ frontmatter: {
+ path: `another-custom-path`,
+ },
+ excerpt: `post description`,
+ },
+ },
+ ],
+ },
+ },
+ })
+ const customQuery = `
+ {
+ allMarkdownRemark(
+ limit: 1000,
+ ) {
+ edges {
+ node {
+ frontmatter {
+ path
+ }
+ excerpt
+ }
+ }
+ }
+ }
+ `
+ const options = {
+ feeds: [
+ {
+ output: `rss.xml`,
+ title: `feed title`,
+ language: `en`,
+ generator: `custom generator`,
+ query: customQuery,
+ serialize: ({ query: { site, allMarkdownRemark } }) =>
+ allMarkdownRemark.edges.map(edge => {
+ return {
+ ...edge.node.frontmatter,
+ description: edge.node.excerpt,
+ url: site.siteMetadata.siteUrl + edge.node.frontmatter.path,
+ }
+ }),
+ },
+ ],
+ }
+ await onPostBuild({ graphql }, options)
+ const [filePath, contents] = fs.writeFile.mock.calls[0]
+ expect(filePath).toEqual(path.join(`public`, `rss.xml`))
+ expect(contents).toMatchSnapshot()
+ })
+
it(`custom query runs`, async () => {
fs.writeFile = jest.fn()
fs.writeFile.mockResolvedValue(true)
@@ -194,6 +282,7 @@ describe(`Test plugin feed`, async () => {
}
}),
query: customQuery,
+ title: `my feed`,
},
],
}
diff --git a/packages/gatsby-plugin-feed/src/internals.js b/packages/gatsby-plugin-feed/src/internals.js
index 19b686e023c3e..f1cb89ed9d8e3 100644
--- a/packages/gatsby-plugin-feed/src/internals.js
+++ b/packages/gatsby-plugin-feed/src/internals.js
@@ -29,8 +29,8 @@ export const defaultOptions = {
setup: ({
query: {
site: { siteMetadata },
- ...rest
},
+ ...rest
}) => {
return {
...siteMetadata,
@@ -69,9 +69,6 @@ export const defaultOptions = {
// Where we will save the feed generated by this query.
output: `rss.xml`,
-
- // Use a title when reference a RSS feed in Link element.
- title: null,
},
],
}
diff --git a/packages/gatsby-plugin-feed/src/plugin-options.js b/packages/gatsby-plugin-feed/src/plugin-options.js
index 095c062e4e470..b716706b0bd47 100644
--- a/packages/gatsby-plugin-feed/src/plugin-options.js
+++ b/packages/gatsby-plugin-feed/src/plugin-options.js
@@ -4,7 +4,7 @@ import Joi from "@hapi/joi"
const feed = Joi.object({
output: Joi.string().required(),
query: Joi.string().required(),
- title: Joi.string(),
+ title: Joi.string().required(),
serialize: Joi.func(),
match: Joi.string(),
}).unknown(true)