Skip to content

Commit b00d2b6

Browse files
committed
Swap dependency to local-search
1 parent d7977f0 commit b00d2b6

File tree

3 files changed

+99
-28
lines changed

3 files changed

+99
-28
lines changed

theme/gatsby-config.js

Lines changed: 69 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,78 @@ module.exports = ({
4343
`gatsby-plugin-react-helmet`,
4444
`gatsby-plugin-sharp`,
4545
{
46-
resolve: `@gatsby-contrib/gatsby-plugin-elasticlunr-search`,
46+
resolve: 'gatsby-plugin-local-search',
4747
options: {
48-
// don't index anything if search is off
49-
// this retains schema entries but stops the effort.
50-
fields: search ? [`title`, `description`, `content`] : [],
51-
resolvers: {
52-
Docs: {
53-
title: (node) => node.title,
54-
description: (node) => node.metaDescription,
55-
// TODO: This is the full raw body, including front matter
56-
content: (node) => node.rawBody,
57-
slug: (node) => node.slug,
58-
},
59-
},
60-
// TODO: Optional filter here, which would be useful for drafts?
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+
`,
72+
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+
})),
6198
},
6299
},
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+
// },
63118
{
64119
resolve: `gatsby-plugin-layout`,
65120
options: {

theme/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@
2929
"dependencies": {
3030
"@committed/components": "^4.2.1",
3131
"@committed/layout": "^4.2.0",
32-
"@gatsby-contrib/gatsby-plugin-elasticlunr-search": "^3.0.2",
3332
"@material-ui/core": "^4.11.0",
3433
"@material-ui/icons": "^4.11.2",
3534
"@material-ui/lab": "^4.0.0-alpha.56",
3635
"@mdx-js/mdx": "^1.6.22",
3736
"@mdx-js/react": "^1.6.22",
3837
"gatsby-plugin-layout": "^2.8.0",
38+
"gatsby-plugin-local-search": "^2.0.1",
3939
"gatsby-plugin-material-ui": "^3.0.1",
4040
"gatsby-plugin-mdx": "^2.8.0",
4141
"gatsby-plugin-react-helmet": "^4.8.0",
@@ -52,6 +52,7 @@
5252
"puppeteer": "^10.0.0",
5353
"react-helmet": "^6.1.0",
5454
"react-hotkeys-hook": "^3.3.2",
55+
"react-use-flexsearch": "^0.1.1",
5556
"remark-emoji": "^2.2.0",
5657
"remark-slug": "^6.0.0",
5758
"typeface-dosis": "^1.1.13",

yarn.lock

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1216,13 +1216,6 @@
12161216
minimatch "^3.0.4"
12171217
strip-json-comments "^3.1.1"
12181218

1219-
"@gatsby-contrib/gatsby-plugin-elasticlunr-search@^3.0.2":
1220-
version "3.0.2"
1221-
resolved "https://registry.yarnpkg.com/@gatsby-contrib/gatsby-plugin-elasticlunr-search/-/gatsby-plugin-elasticlunr-search-3.0.2.tgz#f60462f5f6283af170a22b28e2f159dd936f6a7b"
1222-
integrity sha512-GQUwjZ6/Q6jFl5Kk1zDtquQewbjX4dsLE8g0/V/aA7s5Mvtc7plCYtvSdarqkJdfC41VC31NubHseDqUkoKeRA==
1223-
dependencies:
1224-
elasticlunr "^0.9.5"
1225-
12261219
"@gatsbyjs/reach-router@^1.3.6":
12271220
version "1.3.6"
12281221
resolved "https://registry.yarnpkg.com/@gatsbyjs/reach-router/-/reach-router-1.3.6.tgz#4e8225836959be247890b66f21a3198a0589e34d"
@@ -5388,11 +5381,6 @@ [email protected]:
53885381
resolved "https://registry.yarnpkg.com/ee-first/-/ee-first-1.1.1.tgz#590c61156b0ae2f4f0255732a158b266bc56b21d"
53895382
integrity sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0=
53905383

5391-
elasticlunr@^0.9.5:
5392-
version "0.9.5"
5393-
resolved "https://registry.yarnpkg.com/elasticlunr/-/elasticlunr-0.9.5.tgz#65541bb309dddd0cf94f2d1c8861b2be651bb0d5"
5394-
integrity sha1-ZVQbswnd3Qz5Ty0ciGGyvmUbsNU=
5395-
53965384
electron-to-chromium@^1.3.413:
53975385
version "1.3.427"
53985386
resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.427.tgz#ea43d02908a8c71f47ebb46e09de5a3cf8236f04"
@@ -6490,6 +6478,11 @@ flatted@^3.1.0:
64906478
resolved "https://registry.yarnpkg.com/flatted/-/flatted-3.1.1.tgz#c4b489e80096d9df1dfc97c79871aea7c617c469"
64916479
integrity sha512-zAoAQiudy+r5SvnSw3KJy5os/oRJYHzrzja/tBDqrZtNhUw8bt6y8OBzMWcjWr+8liV8Eb6yOhw8WZ7VFZ5ZzA==
64926480

6481+
flexsearch@^0.6.22, flexsearch@^0.6.32:
6482+
version "0.6.32"
6483+
resolved "https://registry.yarnpkg.com/flexsearch/-/flexsearch-0.6.32.tgz#1e20684d317af65baa445cdd9864a5f5b320f510"
6484+
integrity sha512-EF1BWkhwoeLtbIlDbY/vDSLBen/E5l/f1Vg7iX5CDymQCamcx1vhlc3tIZxIDplPjgi0jhG37c67idFbjg+v+Q==
6485+
64936486
follow-redirects@^1.0.0:
64946487
version "1.11.0"
64956488
resolved "https://registry.yarnpkg.com/follow-redirects/-/follow-redirects-1.11.0.tgz#afa14f08ba12a52963140fe43212658897bc0ecb"
@@ -6732,6 +6725,16 @@ gatsby-plugin-layout@^2.8.0:
67326725
dependencies:
67336726
"@babel/runtime" "^7.14.0"
67346727

6728+
gatsby-plugin-local-search@^2.0.1:
6729+
version "2.0.1"
6730+
resolved "https://registry.yarnpkg.com/gatsby-plugin-local-search/-/gatsby-plugin-local-search-2.0.1.tgz#adf0aeff4b06feee57574420369ca0950a4bcdf7"
6731+
integrity sha512-qrApdH2IYfHL+dSmcwSzhDPVxlkt13N0IfEkKxfWf0gITmBwObOJBYAMnYiYUmP0dpYmSV9anJE//SLZBSsisA==
6732+
dependencies:
6733+
flexsearch "^0.6.32"
6734+
lodash "^4.17.19"
6735+
lunr "^2.3.8"
6736+
pascal-case "^3.1.1"
6737+
67356738
gatsby-plugin-manifest@^3.8.0:
67366739
version "3.8.0"
67376740
resolved "https://registry.yarnpkg.com/gatsby-plugin-manifest/-/gatsby-plugin-manifest-3.8.0.tgz#11d3ff6532b8edf58d18acfd7121a5fe097a0c80"
@@ -9556,6 +9559,11 @@ lru-queue@^0.1.0:
95569559
dependencies:
95579560
es5-ext "~0.10.2"
95589561

9562+
lunr@^2.3.8:
9563+
version "2.3.9"
9564+
resolved "https://registry.yarnpkg.com/lunr/-/lunr-2.3.9.tgz#18b123142832337dd6e964df1a5a7707b25d35e1"
9565+
integrity sha512-zTU3DaZaF3Rt9rhN3uBMGQD3dD2/vFQqnvZCDv4dl5iOzq2IZQqTxu90r4E5J+nP70J3ilqVCrbho2eWaeW8Ow==
9566+
95599567
make-dir@^1.0.0, make-dir@^1.2.0:
95609568
version "1.3.0"
95619569
resolved "https://registry.yarnpkg.com/make-dir/-/make-dir-1.3.0.tgz#79c1033b80515bd6d24ec9933e860ca75ee27f0c"
@@ -11025,7 +11033,7 @@ pascal-case@^2.0.0:
1102511033
camel-case "^3.0.0"
1102611034
upper-case-first "^1.1.0"
1102711035

11028-
pascal-case@^3.1.2:
11036+
pascal-case@^3.1.1, pascal-case@^3.1.2:
1102911037
version "3.1.2"
1103011038
resolved "https://registry.yarnpkg.com/pascal-case/-/pascal-case-3.1.2.tgz#b48e0ef2b98e205e7c1dae747d0b1508237660eb"
1103111039
integrity sha512-uWlGT3YSnK9x3BQJaOdcZwrnV6hPpd8jFH1/ucpiLRPh/2zCVJKS19E4GvYHvaCcACn3foXZ0cLB9Wrx1KGe5g==
@@ -11988,6 +11996,13 @@ react-transition-group@^4.4.0:
1198811996
loose-envify "^1.4.0"
1198911997
prop-types "^15.6.2"
1199011998

11999+
react-use-flexsearch@^0.1.1:
12000+
version "0.1.1"
12001+
resolved "https://registry.yarnpkg.com/react-use-flexsearch/-/react-use-flexsearch-0.1.1.tgz#2db48989a9197ee3d9776a6c2ae1ff6e65919ba2"
12002+
integrity sha512-UDRDB26HPcAo0gXNkUYYkcjoYCW4FSWr7Ich4adgVr7bqefJG7fnjlcqnwsKQkbZuteRLYzzox+1FKRTt3Z5vg==
12003+
dependencies:
12004+
flexsearch "^0.6.22"
12005+
1199112006
react@^17.0.2:
1199212007
version "17.0.2"
1199312008
resolved "https://registry.yarnpkg.com/react/-/react-17.0.2.tgz#d0b5cc516d29eb3eee383f75b62864cfb6800037"

0 commit comments

Comments
 (0)