From e0965d77e9d7cd4439703b337109a6c08b3db865 Mon Sep 17 00:00:00 2001 From: Preston Richey Date: Sat, 7 Nov 2020 09:04:58 -0500 Subject: [PATCH] feat(indexing): add skipIndexing flag (#99) * Add skipIndexing flag * Add to README * Update README.md Co-authored-by: Haroen Viaene Co-authored-by: Haroen Viaene --- README.md | 1 + gatsby-node.js | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index f75fe48..c3c61a0 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,7 @@ module.exports = { enablePartialUpdates: true, // default: false matchFields: ['slug', 'modified'], // Array default: ['modified'] concurrentQueries: false, // default: true + skipIndexing: true, // default: false, useful for e.g. preview deploys or local development }, }, ], diff --git a/gatsby-node.js b/gatsby-node.js index 25572d9..446a488 100644 --- a/gatsby-node.js +++ b/gatsby-node.js @@ -26,11 +26,23 @@ function fetchAlgoliaObjects(index, attributesToRetrieve = ['modified']) { } exports.onPostBuild = async function ({ graphql }, config) { - const { appId, apiKey, queries, concurrentQueries = true } = config; + const { + appId, + apiKey, + queries, + concurrentQueries = true, + skipIndexing = false + } = config; const activity = report.activityTimer(`index to Algolia`); activity.start(); + if (skipIndexing === true) { + setStatus(activity, `options.skipIndexing is true; skipping indexing`); + activity.end(); + return; + } + const client = algoliasearch(appId, apiKey); setStatus(activity, `${queries.length} queries to index`); @@ -61,6 +73,7 @@ exports.onPostBuild = async function ({ graphql }, config) { } catch (err) { report.panic('failed to index to Algolia', err); } + activity.end(); };