@@ -6,7 +6,7 @@ module.exports = ({
66 sidebar,
77 print,
88 checkLinks = { } ,
9- search = false ,
9+ search = true ,
1010} ) => ( {
1111 siteMetadata : {
1212 title : 'Docs' ,
@@ -42,79 +42,7 @@ module.exports = ({
4242 `gatsby-plugin-material-ui` ,
4343 `gatsby-plugin-react-helmet` ,
4444 `gatsby-plugin-sharp` ,
45- {
46- resolve : 'gatsby-plugin-local-search' ,
47- options : {
48- // A unique name for the search index. This should be descriptive of
49- // what the index contains. This is required.
50- name : 'pages' ,
51-
52- // Set the search engine to create the index. This is required.
53- // The following engines are supported: flexsearch, lunr
54- engine : 'flexsearch' ,
55-
56- // GraphQL query used to fetch all data for the search index. This is
57- // required.
58- query : `
59- {
60- allMarkdownRemark {
61- nodes {
62- id
63- frontmatter {
64- path
65- title
66- }
67- rawMarkdownBody
68- }
69- }
70- }
71- ` ,
7245
73- // Field used as the reference value for each document.
74- // Default: 'id'.
75- ref : 'id' ,
76-
77- // List of keys to index. The values of the keys are taken from the
78- // normalizer function below.
79- // Default: all fields
80- index : [ 'title' , 'description' , 'body' ] ,
81-
82- // List of keys to store and make available in your UI. The values of
83- // the keys are taken from the normalizer function below.
84- // Default: all fields
85- store : [ 'title' , 'id' , 'description' ] ,
86-
87- // Function used to map the result from the GraphQL query. This should
88- // return an array of items to index in the form of flat objects
89- // containing properties to index. The objects must contain the `ref`
90- // field above (default: 'id'). This is required.
91- normalizer : ( { data } ) =>
92- data . allMarkdownRemark . nodes . map ( ( node ) => ( {
93- id : node . id ,
94- path : node . frontmatter . path ,
95- title : node . frontmatter . title ,
96- body : node . rawMarkdownBody ,
97- } ) ) ,
98- } ,
99- } ,
100- // {
101- // resolve: `@gatsby-contrib/gatsby-plugin-elasticlunr-search`,
102- // options: {
103- // // don't index anything if search is off
104- // // this retains schema entries but stops the effort.
105- // fields: search ? [`title`, `description`, `content`] : [],
106- // resolvers: {
107- // Docs: {
108- // title: (node) => node.title,
109- // description: (node) => node.metaDescription,
110- // // TODO: This is the full raw body, including front matter
111- // content: (node) => node.rawBody,
112- // slug: (node) => node.slug,
113- // },
114- // },
115- // // TODO: Optional filter here, which would be useful for drafts?
116- // },
117- // },
11846 {
11947 resolve : `gatsby-plugin-layout` ,
12048 options : {
@@ -186,5 +114,64 @@ module.exports = ({
186114 ] ,
187115 } ,
188116 } ,
117+ {
118+ resolve : 'gatsby-plugin-local-search' ,
119+ options : {
120+ // A unique name for the search index. This should be descriptive of
121+ // what the index contains. This is required.
122+ name : 'pages' ,
123+
124+ // Set the search engine to create the index. This is required.
125+ // The following engines are supported: flexsearch, lunr
126+ engine : 'flexsearch' ,
127+
128+ // GraphQL query used to fetch all data for the search index. This is
129+ // required.
130+ query : `
131+ {
132+ allMdx {
133+ nodes {
134+ id
135+ slug
136+ frontmatter {
137+ title
138+ metaDescription
139+ }
140+ excerpt
141+ rawBody
142+ }
143+ }
144+ }
145+ ` ,
146+
147+ // Field used as the reference value for each document.
148+ // Default: 'id'.
149+ ref : 'id' ,
150+
151+ // List of keys to index. The values of the keys are taken from the
152+ // normalizer function below.
153+ // Default: all fields
154+ index : [ 'title' , 'description' , 'body' ] ,
155+
156+ // List of keys to store and make available in your UI. The values of
157+ // the keys are taken from the normalizer function below.
158+ // Default: all fields
159+ store : [ 'id' , 'slug' , 'title' , 'description' , 'excerpt' ] ,
160+
161+ // Function used to map the result from the GraphQL query. This should
162+ // return an array of items to index in the form of flat objects
163+ // containing properties to index. The objects must contain the `ref`
164+ // field above (default: 'id'). This is required.
165+ normalizer : ( { data } ) =>
166+ data . allMdx . nodes . map ( ( node ) => ( {
167+ id : node . id ,
168+ slug : node . slug ,
169+ title : node . frontmatter . title ,
170+ description : node . frontmatter . description ,
171+ excerpt : node . excerpt ,
172+ body : node . rawBody ,
173+ } ) ) ,
174+ } ,
175+ } ,
189176 ] ,
190177} )
0 commit comments