Skip to content

Commit

Permalink
feat: add ability to filter which pages are fetched
Browse files Browse the repository at this point in the history
  • Loading branch information
jerelmiller committed Aug 12, 2020
1 parent 10b2f78 commit da64b13
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
8 changes: 8 additions & 0 deletions plugins/gatsby-source-swiftype/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
};

0 comments on commit da64b13

Please sign in to comment.