From 50d97302bae1ade90aa9d68ab53050e39f9ee532 Mon Sep 17 00:00:00 2001 From: Steven Thompson Date: Fri, 29 Sep 2023 18:06:33 +0100 Subject: [PATCH] feat(gatsbynode): add onlyLanguages option --- src/gatsby-node.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/gatsby-node.js b/src/gatsby-node.js index 21ea3bb..ebad27b 100644 --- a/src/gatsby-node.js +++ b/src/gatsby-node.js @@ -91,11 +91,19 @@ exports.onCreatePage = async ({ page, actions }, pluginOptions) => { } } - const newPage = generatePage(false, defaultLanguage) + const options = page.context.gatsbyPluginIntl || {} + const onlyLanguages = options.onlyLanguages || [] + deletePage(page) - createPage(newPage) + + if (onlyLanguages.length === 0 || onlyLanguages.includes(defaultLanguage)) { + const newPage = generatePage(false, defaultLanguage) + createPage(newPage) + } languages.forEach((language) => { + if (onlyLanguages.length > 0 && !onlyLanguages.includes(language)) + return; const localePage = generatePage(true, language) const regexp = new RegExp("/404/?$") if (regexp.test(localePage.path)) {