Skip to content

Commit

Permalink
feat: add an option to resolve locales in entries referenced by rich …
Browse files Browse the repository at this point in the history
…text (#21619)

* feat: add an option to resolve locales in entries referenced by rich text

* fix: remove unnecessary default value

* feat: only use locale resolution if richText.resolveFieldLocales is true

* perf: pass in content types keyed by ID rather than looking them up for each entry

* docs: document the new option in the README

* perf: use a set instead of an array to track resolved entry IDs

* perf: use a Map to keep track of content types by ID
  • Loading branch information
jessepinho committed Feb 21, 2020
1 parent e985d8e commit 0666df7
Show file tree
Hide file tree
Showing 10 changed files with 590 additions and 7 deletions.
4 changes: 4 additions & 0 deletions packages/gatsby-source-contentful/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ If you are confident your Content Types will have natural-language IDs (e.g. `bl

Number of entries to retrieve from Contentful at a time. Due to some technical limitations, the response payload should not be greater than 7MB when pulling content from Contentful. If you encounter this issue you can set this param to a lower number than 100, e.g `50`.

**`richText.resolveFieldLocales`** [boolean][optional] [default: `false`]

If you want to resolve the locales in fields of assets and entries that are referenced by rich text (e.g., via embedded entries or entry hyperlinks), set this to `true`. Otherwise, fields of referenced assets or entries will be objects keyed by locale.

## 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/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
},
"dependencies": {
"@babel/runtime": "^7.7.6",
"@contentful/rich-text-types": "^13.1.0",
"@hapi/joi": "^15.1.1",
"axios": "^0.19.0",
"base64-img": "^1.0.4",
Expand Down
4 changes: 2 additions & 2 deletions packages/gatsby-source-contentful/src/__tests__/normalize.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe(`Process contentful data (by name)`, () => {
createNodeId.mockReturnValue(`uuid-from-gatsby`)
contentTypeItems.forEach((contentTypeItem, i) => {
entryList[i].forEach(normalize.fixIds)
normalize.createContentTypeNodes({
normalize.createNodesForContentType({
contentTypeItem,
restrictedNodeFields,
conflictFieldPrefix,
Expand Down Expand Up @@ -139,7 +139,7 @@ describe(`Process contentful data (by id)`, () => {
createNodeId.mockReturnValue(`uuid-from-gatsby`)
contentTypeItems.forEach((contentTypeItem, i) => {
entryList[i].forEach(normalize.fixIds)
normalize.createContentTypeNodes({
normalize.createNodesForContentType({
contentTypeItem,
restrictedNodeFields,
conflictFieldPrefix,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ describe(`Options validation`, () => {
downloadLocal: 5,
useNameForId: 5,
pageLimit: `fifty`,
richText: true,
}
)

Expand Down Expand Up @@ -203,6 +204,9 @@ describe(`Options validation`, () => {
expect(reporter.panic).toBeCalledWith(
expect.stringContaining(`"pageLimit" must be a number`)
)
expect(reporter.panic).toBeCalledWith(
expect.stringContaining(`"richText" must be an object`)
)
})

it(`Fails with undefined option keys`, () => {
Expand Down
Loading

0 comments on commit 0666df7

Please sign in to comment.