Skip to content

Commit

Permalink
feat: add config to enable swiftype builds using env variable
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Aug 13, 2020
1 parent 7a4c0e5 commit 6d77c70
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ module.exports = {
resolve: 'gatsby-source-swiftype',
options: {
file: `${__dirname}/src/data/related-pages.json`,
enabled: Boolean(process.env.BUILD_RELATED_CONTENT),
engineKey: 'Ad9HfGjDw4GRkcmJjUut',
pageLimit: 5,
getPath: ({ node }) => node.frontmatter.path,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
"build": "gatsby build",
"build:production": "GATSBY_NEWRELIC_ENV=production gatsby build",
"build:staging": "GATSBY_NEWRELIC_ENV=staging gatsby build",
"build:related-content": "BUILD_RELATED_CONTENT=true npm run build:production",
"develop": "gatsby develop",
"format": "prettier --write \"**/*.{js,jsx,json,md}\"",
"start": "npm run develop",
Expand Down
9 changes: 6 additions & 3 deletions plugins/gatsby-source-swiftype/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ const data = {};

exports.onCreateNode = async ({ node, getNodesByType }, pluginOptions) => {
const {
enabled,
filterNode = () => false,
getParams,
getPath,
pageLimit,
engineKey,
} = pluginOptions;

if (!filterNode({ node })) {
if (!enabled || !filterNode({ node })) {
return;
}

Expand Down Expand Up @@ -61,7 +62,9 @@ exports.onCreateNode = async ({ node, getNodesByType }, pluginOptions) => {
};

exports.onPostBootstrap = (_, pluginOptions) => {
const { file } = pluginOptions;
const { file, enabled } = pluginOptions;

fs.writeFileSync(file, JSON.stringify(data, null, 2), { flag: 'w' });
if (enabled) {
fs.writeFileSync(file, JSON.stringify(data, null, 2), { flag: 'w' });
}
};

0 comments on commit 6d77c70

Please sign in to comment.