File tree 3 files changed +40
-12
lines changed
3 files changed +40
-12
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' @primer/gatsby-theme-doctocat ' : minor
3
+ ---
4
+
5
+ Ability to add custom docs to search
Original file line number Diff line number Diff line change @@ -9,6 +9,17 @@ const mdx = require(`gatsby-plugin-mdx/utils/mdx`)
9
9
10
10
const CONTRIBUTOR_CACHE = new Map ( )
11
11
12
+ exports . createSchemaCustomization = async ( { actions} ) => {
13
+ const typeDefs = `
14
+ type CustomSearchDoc implements Node {
15
+ path: String!
16
+ title: String!
17
+ rawBody: String!
18
+ }
19
+ `
20
+ actions . createTypes ( typeDefs )
21
+ }
22
+
12
23
exports . createPages = async ( { graphql, actions} , themeOptions ) => {
13
24
const repo = getPkgRepo ( readPkgUp . sync ( ) . package )
14
25
Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ function useSearch(query) {
10
10
const workerRef = React . useRef ( )
11
11
12
12
const data = useStaticQuery ( graphql `
13
- {
13
+ query {
14
14
allMdx {
15
15
nodes {
16
16
fileAbsolutePath
@@ -26,20 +26,32 @@ function useSearch(query) {
26
26
}
27
27
}
28
28
}
29
+
30
+ allCustomSearchDoc {
31
+ nodes {
32
+ path
33
+ title
34
+ rawBody
35
+ }
36
+ }
29
37
}
30
38
` )
31
39
32
- const list = React . useMemo (
33
- ( ) =>
34
- data . allMdx . nodes . map ( node => ( {
35
- path : ensureAbsolute (
36
- path . join ( node . parent . relativeDirectory , node . parent . name === 'index' ? '/' : node . parent . name )
37
- ) ,
38
- title : node . frontmatter . title ,
39
- rawBody : node . rawBody
40
- } ) ) ,
41
- [ data ]
42
- )
40
+ const list = React . useMemo ( ( ) => {
41
+ const results = data . allMdx . nodes . map ( node => ( {
42
+ path : ensureAbsolute (
43
+ path . join ( node . parent . relativeDirectory , node . parent . name === 'index' ? '/' : node . parent . name )
44
+ ) ,
45
+ title : node . frontmatter . title ,
46
+ rawBody : node . rawBody
47
+ } ) )
48
+
49
+ if ( data . allCustomSearchDoc . nodes ) {
50
+ results . push ( ...data . allCustomSearchDoc . nodes )
51
+ }
52
+
53
+ return results
54
+ } , [ data ] )
43
55
44
56
const [ results , setResults ] = React . useState ( list )
45
57
You can’t perform that action at this time.
0 commit comments