Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(gatsby-source-contentful): add locale filter #12939

Merged
merged 10 commits into from
Apr 16, 2019
8 changes: 8 additions & 0 deletions packages/gatsby-source-contentful/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'`
pieh marked this conversation as resolved.
Show resolved Hide resolved

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.
Expand Down
1 change: 1 addition & 0 deletions packages/gatsby-source-contentful/src/fetch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down