From da64b13713e266d0cbd7c0b0ea72809aa9f569d9 Mon Sep 17 00:00:00 2001 From: Jerel Miller Date: Wed, 12 Aug 2020 16:38:29 -0700 Subject: [PATCH] feat: add ability to filter which pages are fetched --- gatsby-config.js | 2 ++ plugins/gatsby-source-swiftype/gatsby-node.js | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/gatsby-config.js b/gatsby-config.js index c071f33b6..ba7ecf420 100644 --- a/gatsby-config.js +++ b/gatsby-config.js @@ -46,6 +46,8 @@ module.exports = { resolve: 'gatsby-source-swiftype', options: { path: `${__dirname}/src/data`, + filterPage: ({ page }) => + page.component === `${__dirname}/src/templates/GuideTemplate.js`, }, }, 'gatsby-plugin-sass', diff --git a/plugins/gatsby-source-swiftype/gatsby-node.js b/plugins/gatsby-source-swiftype/gatsby-node.js index 68f2abb1e..6b312d62c 100644 --- a/plugins/gatsby-source-swiftype/gatsby-node.js +++ b/plugins/gatsby-source-swiftype/gatsby-node.js @@ -9,3 +9,11 @@ exports.onPreBootstrap = ({ reporter }, pluginOptions) => { fs.writeFileSync(dataFile, ''); } }; + +exports.onCreatePage = async ({ page }, pluginOptions) => { + const includePage = pluginOptions.filterPage || (() => false); + + if (includePage({ page })) { + console.log(`Fetching ${page.path}`); + } +};