Skip to content

Commit 435a862

Browse files
committed
Add rawBody to the Docs node (to search on)
1 parent ebcb730 commit 435a862

File tree

1 file changed

+32
-28
lines changed

1 file changed

+32
-28
lines changed

theme/gatsby-node.js

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,59 +20,62 @@ exports.sourceNodes = ({ actions, schema }) => {
2020
fields: {
2121
id: { type: `ID!` },
2222
slug: {
23-
type: 'String!'
23+
type: 'String!',
2424
},
2525
title: {
26-
type: 'String!'
26+
type: 'String!',
2727
},
2828
metaTitle: {
29-
type: 'String!'
29+
type: 'String!',
3030
},
3131
metaDescription: {
32-
type: 'String!'
32+
type: 'String!',
3333
},
3434
order: {
35-
type: 'String!'
35+
type: 'String!',
3636
},
3737
tableOfContents: {
3838
type: 'Json!',
3939
resolve(source, args, context, info) {
4040
const type = info.schema.getType(`Mdx`)
4141
const mdxNode = context.nodeModel.getNodeById({
42-
id: source.parent
42+
id: source.parent,
4343
})
4444
const resolver = type.getFields()['tableOfContents'].resolve
4545
return resolver(mdxNode, {}, context, {
46-
fieldName: 'tableOfContents'
46+
fieldName: 'tableOfContents',
4747
})
48-
}
48+
},
4949
},
5050
body: {
5151
type: 'String!',
5252
resolve(source, args, context, info) {
5353
const type = info.schema.getType(`Mdx`)
5454
const mdxNode = context.nodeModel.getNodeById({
55-
id: source.parent
55+
id: source.parent,
5656
})
5757
const resolver = type.getFields()['body'].resolve
5858
return resolver(mdxNode, {}, context, {
59-
fieldName: 'body'
59+
fieldName: 'body',
6060
})
61-
}
62-
}
61+
},
62+
},
63+
rawBody: {
64+
type: 'String!',
65+
},
6366
},
64-
interfaces: [`Node`]
67+
interfaces: [`Node`],
6568
}),
6669
schema.buildObjectType({
6770
name: `Menu`,
6871
fields: {
6972
id: { type: `ID!` },
7073
data: {
71-
type: 'Json!'
72-
}
74+
type: 'Json!',
75+
},
7376
},
74-
interfaces: [`Node`]
75-
})
77+
interfaces: [`Node`],
78+
}),
7679
])
7780
}
7881

@@ -98,7 +101,7 @@ exports.createPages = async (
98101
}
99102
}
100103
`
101-
).then(result => {
104+
).then((result) => {
102105
if (result.errors) {
103106
reporter.panicOnBuild(`Error while running GraphQL query.`)
104107
return
@@ -135,8 +138,8 @@ exports.createPages = async (
135138
current: item,
136139
id: item.id,
137140
previous,
138-
next
139-
}
141+
next,
142+
},
140143
})
141144
})
142145

@@ -150,7 +153,7 @@ exports.createPages = async (
150153
})
151154

152155
const fieldData = {
153-
data: treeData
156+
data: treeData,
154157
}
155158

156159
createNode({
@@ -162,8 +165,8 @@ exports.createPages = async (
162165
type: `Menu`,
163166
content: JSON.stringify(fieldData),
164167
description: `Menu`,
165-
contentDigest: createContentDigest(fieldData)
166-
}
168+
contentDigest: createContentDigest(fieldData),
169+
},
167170
})
168171
})
169172
)
@@ -189,7 +192,7 @@ exports.onCreateNode = ({
189192
getNode,
190193
createNodeId,
191194
createContentDigest,
192-
reporter
195+
reporter,
193196
}) => {
194197
const { createNode, createParentChildLink } = actions
195198
if (node.internal.type === `Mdx`) {
@@ -213,7 +216,8 @@ exports.onCreateNode = ({
213216
metaTitle: node.frontmatter.metaTitle || title,
214217
metaDescription: node.frontmatter.metaDescription || '',
215218
order: node.frontmatter.order || title,
216-
tableOfContents: node.tableOfContents
219+
tableOfContents: node.tableOfContents,
220+
rawBody: node.rawBody,
217221
}
218222

219223
createNode({
@@ -226,12 +230,12 @@ exports.onCreateNode = ({
226230
type: `Docs`,
227231
content: JSON.stringify(fieldData),
228232
description: `Documentation`,
229-
contentDigest: createContentDigest(fieldData)
230-
}
233+
contentDigest: createContentDigest(fieldData),
234+
},
231235
})
232236
createParentChildLink({
233237
parent: parent,
234-
child: node
238+
child: node,
235239
})
236240
}
237241
}

0 commit comments

Comments
 (0)