@@ -20,65 +20,68 @@ 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
7982exports . createPages = async (
8083 { actions, graphql, reporter, createContentDigest } ,
81- options
84+ { sidebar , search = true }
8285) => {
8386 const { createPage, createNode } = actions
8487 return new Promise ( ( resolve , reject ) => {
@@ -98,16 +101,13 @@ 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
105108 }
106109
107- const treeData = calculateTreeData (
108- options . sidebar ,
109- result . data . allDocs . edges
110- )
110+ const treeData = calculateTreeData ( sidebar , result . data . allDocs . edges )
111111
112112 const data = flattenTree ( treeData )
113113
@@ -135,8 +135,8 @@ exports.createPages = async (
135135 current : item ,
136136 id : item . id ,
137137 previous,
138- next
139- }
138+ next,
139+ } ,
140140 } )
141141 } )
142142
@@ -145,12 +145,23 @@ exports.createPages = async (
145145 component : path . resolve ( `${ __dirname } /src/layout/print.tsx` ) ,
146146 context : {
147147 layout : 'print' ,
148- data
149- }
148+ data,
149+ } ,
150150 } )
151151
152+ if ( search ) {
153+ createPage ( {
154+ path : '/search' ,
155+ component : path . resolve ( `${ __dirname } /src/layout/search.tsx` ) ,
156+ context : {
157+ layout : 'docs' ,
158+ data,
159+ } ,
160+ } )
161+ }
162+
152163 const fieldData = {
153- data : treeData
164+ data : treeData ,
154165 }
155166
156167 createNode ( {
@@ -162,8 +173,8 @@ exports.createPages = async (
162173 type : `Menu` ,
163174 content : JSON . stringify ( fieldData ) ,
164175 description : `Menu` ,
165- contentDigest : createContentDigest ( fieldData )
166- }
176+ contentDigest : createContentDigest ( fieldData ) ,
177+ } ,
167178 } )
168179 } )
169180 )
@@ -189,7 +200,7 @@ exports.onCreateNode = ({
189200 getNode,
190201 createNodeId,
191202 createContentDigest,
192- reporter
203+ reporter,
193204} ) => {
194205 const { createNode, createParentChildLink } = actions
195206 if ( node . internal . type === `Mdx` ) {
@@ -213,7 +224,8 @@ exports.onCreateNode = ({
213224 metaTitle : node . frontmatter . metaTitle || title ,
214225 metaDescription : node . frontmatter . metaDescription || '' ,
215226 order : node . frontmatter . order || title ,
216- tableOfContents : node . tableOfContents
227+ tableOfContents : node . tableOfContents ,
228+ rawBody : node . rawBody ,
217229 }
218230
219231 createNode ( {
@@ -226,13 +238,23 @@ exports.onCreateNode = ({
226238 type : `Docs` ,
227239 content : JSON . stringify ( fieldData ) ,
228240 description : `Documentation` ,
229- contentDigest : createContentDigest ( fieldData )
230- }
241+ contentDigest : createContentDigest ( fieldData ) ,
242+ } ,
231243 } )
232244 createParentChildLink ( {
233245 parent : parent ,
234- child : node
246+ child : node ,
235247 } )
236248 }
237249 }
238250}
251+
252+ exports . createSchemaCustomization = ( { actions } ) => {
253+ const { createTypes } = actions
254+ const typeDefs = `
255+ type AuthorJson implements Node {
256+ joinedAt: Date
257+ }
258+ `
259+ createTypes ( typeDefs )
260+ }
0 commit comments