@@ -20,13 +20,13 @@ function renderReferencedComponent(ref) {
20
20
return < Component { ...ref } />
21
21
}
22
22
23
- const options = {
23
+ const makeOptions = ( { assetBlockMap , entryBlockMap , entryInlineMap } ) => ( {
24
24
renderMark : {
25
25
[ MARKS . BOLD ] : text => < strong data-cy-strong > { text } </ strong > ,
26
26
} ,
27
27
renderNode : {
28
28
[ BLOCKS . EMBEDDED_ASSET ] : node => {
29
- const asset = node . data . target
29
+ const asset = assetBlockMap . get ( node ? .data ? .target ?. sys . id )
30
30
if ( asset . fluid ) {
31
31
return < GatsbyImage { ...asset } style = { { width : 200 } } />
32
32
}
@@ -40,7 +40,7 @@ const options = {
40
40
)
41
41
} ,
42
42
[ BLOCKS . EMBEDDED_ENTRY ] : node => {
43
- const entry = node ?. data ?. target
43
+ const entry = entryBlockMap . get ( node ?. data ?. target ?. sys . id )
44
44
if ( ! entry ) {
45
45
throw new Error (
46
46
`Entity not available for node:\n${ JSON . stringify ( node , null , 2 ) } `
@@ -49,7 +49,7 @@ const options = {
49
49
return renderReferencedComponent ( entry )
50
50
} ,
51
51
[ INLINES . EMBEDDED_ENTRY ] : node => {
52
- const entry = node . data . target
52
+ const entry = entryInlineMap . get ( node ? .data ? .target ?. sys . id )
53
53
if ( entry . __typename === "ContentfulText" ) {
54
54
return (
55
55
< span data-cy-id = "inline-text" >
@@ -64,7 +64,7 @@ const options = {
64
64
)
65
65
} ,
66
66
} ,
67
- }
67
+ } )
68
68
69
69
const RichTextPage = ( { data } ) => {
70
70
const entries = data . allContentfulRichText . nodes
@@ -75,7 +75,7 @@ const RichTextPage = ({ data }) => {
75
75
return (
76
76
< div data-cy-id = { slug } key = { id } >
77
77
< h2 > { title } </ h2 >
78
- { renderRichText ( richText , options ) }
78
+ { renderRichText ( richText , makeOptions ) }
79
79
< hr />
80
80
</ div >
81
81
)
@@ -93,77 +93,94 @@ export const pageQuery = graphql`
93
93
id
94
94
title
95
95
richText {
96
- raw
97
- references {
98
- __typename
99
- sys {
100
- id
101
- }
102
- ... on ContentfulAsset {
103
- fluid(maxWidth: 200) {
104
- ...GatsbyContentfulFluid
105
- }
106
- }
107
- ... on ContentfulText {
108
- title
109
- short
110
- }
111
- ... on ContentfulLocation {
112
- location {
113
- lat
114
- lon
96
+ json
97
+ links {
98
+ assets {
99
+ block {
100
+ sys {
101
+ id
102
+ }
103
+ fluid(maxWidth: 200) {
104
+ ...GatsbyContentfulFluid
105
+ }
115
106
}
116
107
}
117
- ... on ContentfulContentReference {
118
- title
119
- one {
108
+ entries {
109
+ block {
120
110
__typename
121
111
sys {
122
112
id
113
+ type
123
114
}
124
115
... on ContentfulText {
125
116
title
126
117
short
127
118
}
119
+ ... on ContentfulLocation {
120
+ location {
121
+ lat
122
+ lon
123
+ }
124
+ }
128
125
... on ContentfulContentReference {
129
126
title
130
127
one {
128
+ __typename
129
+ sys {
130
+ id
131
+ }
132
+ ... on ContentfulText {
133
+ title
134
+ short
135
+ }
131
136
... on ContentfulContentReference {
132
137
title
138
+ one {
139
+ ... on ContentfulContentReference {
140
+ title
141
+ }
142
+ }
143
+ many {
144
+ ... on ContentfulContentReference {
145
+ title
146
+ }
147
+ }
133
148
}
134
149
}
135
150
many {
151
+ __typename
152
+ sys {
153
+ id
154
+ }
155
+ ... on ContentfulText {
156
+ title
157
+ short
158
+ }
159
+ ... on ContentfulNumber {
160
+ title
161
+ integer
162
+ }
136
163
... on ContentfulContentReference {
137
164
title
165
+ one {
166
+ ... on ContentfulContentReference {
167
+ title
168
+ }
169
+ }
170
+ many {
171
+ ... on ContentfulContentReference {
172
+ title
173
+ }
174
+ }
138
175
}
139
176
}
140
177
}
141
178
}
142
- many {
179
+ inline {
143
180
__typename
144
181
sys {
145
182
id
146
- }
147
- ... on ContentfulText {
148
- title
149
- short
150
- }
151
- ... on ContentfulNumber {
152
- title
153
- integer
154
- }
155
- ... on ContentfulContentReference {
156
- title
157
- one {
158
- ... on ContentfulContentReference {
159
- title
160
- }
161
- }
162
- many {
163
- ... on ContentfulContentReference {
164
- title
165
- }
166
- }
183
+ type
167
184
}
168
185
}
169
186
}
0 commit comments