diff --git a/packages/gatsby-source-contentful/README.md b/packages/gatsby-source-contentful/README.md index 46b397e4b330f..6a83bbb7acf73 100644 --- a/packages/gatsby-source-contentful/README.md +++ b/packages/gatsby-source-contentful/README.md @@ -144,6 +144,14 @@ Downloads and caches `ContentfulAsset`'s to the local filesystem. Allows you to You can pass in any other options available in the [contentful.js SDK](https://github.com/contentful/contentful.js#configuration). +**`localeFilter`** [function][optional] [default: `() => true`] + +Possibility to limit how many locales/nodes are created in graphQL. This can limit the memory usage by reducing the amout of nodes created. Useful if you have a large space in contentful and only want to get the data from one selected locale. + +For example, to filter locales on only germany `localeFilter: locale => locale.code === 'de-DE'` + +List of locales and their codes can be found in Contentful app -> Settings -> Locales + ## Notes on Contentful Content Models There are currently some things to keep in mind when building your content models at Contentful. diff --git a/packages/gatsby-source-contentful/src/fetch.js b/packages/gatsby-source-contentful/src/fetch.js index faaf71c910a23..608791bab5a17 100644 --- a/packages/gatsby-source-contentful/src/fetch.js +++ b/packages/gatsby-source-contentful/src/fetch.js @@ -23,6 +23,7 @@ module.exports = async ({ spaceId, syncToken, ...options }) => { console.log(`Fetching default locale`) locales = await client.getLocales().then(response => response.items) defaultLocale = _.find(locales, { default: true }).code + locales = locales.filter(options.localeFilter || (() => true)) console.log(`default locale is : ${defaultLocale}`) } catch (e) { console.log(