Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions packages/babel-preset-gatsby/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ export function loadCachedConfig() {
export default function preset(_, options = {}) {
let { targets = null } = options

// TODO(v3): Remove process.env.GATSBY_BUILD_STAGE, needs to be passed as an option
const stage = options.stage || process.env.GATSBY_BUILD_STAGE || `test`
const stage = options.stage || `test`
const pluginBabelConfig = loadCachedConfig()
let isBrowser
// unused because of cloud builds
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ exports[`Test plugin feed custom properties work properly 1`] = `"<?xml version=

exports[`Test plugin feed custom query runs 1`] = `"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?><rss xmlns:dc=\\"http://purl.org/dc/elements/1.1/\\" xmlns:content=\\"http://purl.org/rss/1.0/modules/content/\\" xmlns:atom=\\"http://www.w3.org/2005/Atom\\" version=\\"2.0\\"><channel><title><![CDATA[my feed]]></title><description><![CDATA[a description]]></description><link>http://github.com/dylang/node-rss</link><generator>GatsbyJS</generator><lastBuildDate>Mon, 01 Jan 2018 00:00:00 GMT</lastBuildDate><item><title><![CDATA[No title]]></title><description><![CDATA[post description]]></description><link>http://dummy.url/a-custom-path</link><guid isPermaLink=\\"true\\">http://dummy.url/a-custom-path</guid></item><item><title><![CDATA[No title]]></title><description><![CDATA[post description]]></description><link>http://dummy.url/another-custom-path</link><guid isPermaLink=\\"true\\">http://dummy.url/another-custom-path</guid></item></channel></rss>"`;

exports[`Test plugin feed default settings work properly 1`] = `"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?><rss xmlns:dc=\\"http://purl.org/dc/elements/1.1/\\" xmlns:content=\\"http://purl.org/rss/1.0/modules/content/\\" xmlns:atom=\\"http://www.w3.org/2005/Atom\\" version=\\"2.0\\"><channel><title><![CDATA[a sample title]]></title><description><![CDATA[a description]]></description><link>http://github.com/dylang/node-rss</link><generator>GatsbyJS</generator><lastBuildDate>Mon, 01 Jan 2018 00:00:00 GMT</lastBuildDate><item><title><![CDATA[No title]]></title><description><![CDATA[post description]]></description><link>http://dummy.url/a-slug</link><guid isPermaLink=\\"false\\">http://dummy.url/a-slug</guid><content:encoded></content:encoded></item></channel></rss>"`;
39 changes: 6 additions & 33 deletions packages/gatsby-plugin-feed/src/__tests__/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,6 @@ describe(`Test plugin feed`, () => {
fs.mkdirp = jest.fn().mockResolvedValue()
})

it(`default settings work properly`, async () => {
fs.writeFile = jest.fn()
fs.writeFile.mockResolvedValue(true)
const graphql = jest.fn()
graphql.mockResolvedValue({
data: {
site: {
siteMetadata: {
title: `a sample title`,
description: `a description`,
siteUrl: `http://dummy.url/`,
},
},
allMarkdownRemark: {
edges: [
{
node: {
fields: {
slug: `a-slug`,
},
excerpt: `post description`,
},
},
],
},
},
})
await onPostBuild({ graphql }, {})
const [filePath, contents] = fs.writeFile.mock.calls[0]
expect(filePath).toEqual(path.join(`public`, `rss.xml`))
expect(contents).toMatchSnapshot()
})

it(`custom properties work properly`, async () => {
fs.writeFile = jest.fn()
fs.writeFile.mockResolvedValue(true)
Expand Down Expand Up @@ -243,6 +210,12 @@ describe(`Test plugin feed`, () => {
{
output: `rss.xml`,
query: `{ firstMarkdownQuery }`,
serialize: ({ query: { allMarkdownRemark } }) =>
allMarkdownRemark.edges.map(edge => {
return {
...edge.node.frontmatter,
}
}),
},
],
}
Expand Down
20 changes: 1 addition & 19 deletions packages/gatsby-plugin-feed/src/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,6 @@ const publicPath = `./public`

exports.pluginOptionsSchema = pluginOptionsSchema

// TODO: remove in the next major release
// A default function to transform query data into feed entries.
const serialize = ({ query: { site, allMarkdownRemark } }) =>
allMarkdownRemark.edges.map(edge => {
return {
...edge.node.frontmatter,
description: edge.node.excerpt,
url: site.siteMetadata.siteUrl + edge.node.fields.slug,
guid: site.siteMetadata.siteUrl + edge.node.fields.slug,
custom_elements: [{ "content:encoded": edge.node.html }],
}
})

exports.onPostBuild = async ({ graphql }, pluginOptions) => {
/*
* Run the site settings query to gather context, then
Expand All @@ -47,12 +34,7 @@ exports.onPostBuild = async ({ graphql }, pluginOptions) => {
...feed,
}

const serializer =
feed.serialize && typeof feed.serialize === `function`
? feed.serialize
: serialize

const rssFeed = (await serializer(locals)).reduce((merged, item) => {
const rssFeed = (await feed.serialize(locals)).reduce((merged, item) => {
merged.item(item)
return merged
}, new RSS(setup(locals)))
Expand Down
8 changes: 5 additions & 3 deletions packages/gatsby-plugin-google-analytics/src/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
exports.pluginOptionsSchema = ({ Joi }) =>
// TODO: make sure that trackingId gets required() when releasing a major version
Joi.object({
trackingId: Joi.string().description(
`The property ID; the tracking code won't be generated without it`
),
trackingId: Joi.string()
.description(
`The property ID; the tracking code won't be generated without it`
)
.required(),
head: Joi.boolean()
.default(false)
.description(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,17 @@ describe(`Load plugins`, () => {
"configDir": null,
"pluginName": "gatsby-plugin-google-analytics",
"validationErrors": Array [
Object {
"context": Object {
"key": "trackingId",
"label": "trackingId",
},
"message": "\\"trackingId\\" is required",
"path": Array [
"trackingId",
],
"type": "any.required",
},
Object {
"context": Object {
"key": "anonymize",
Expand Down