Skip to content

Commit 37d7e13

Browse files
author
Kirill Bolotsky
committed
fix(algolia): fixed algolia indexing process
- Replaced .flatMap with es5 one-level-deep analog ported from blog - added `matchField` options to algolia config, required after plugin upgrade
1 parent b8fa124 commit 37d7e13

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

gatsby-config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ if (
206206
appId: process.env.GATSBY_ALGOLIA_APP_ID,
207207
apiKey: process.env.ALGOLIA_ADMIN_KEY,
208208
enablePartialUpdates: true,
209+
matchFields: ['title', 'slug', 'content'],
209210
queries,
210211
chunkSize: 10000, // default: 1000
211212
},

src/utils/algolia.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const {
99
dedupePath,
1010
removeGuidesAndRedirectWelcome,
1111
mdxAstToPlainText,
12+
flat,
1213
} = require('./utils');
1314

1415
const processMdxEntry = ({ children: [entry] }) => {
@@ -67,11 +68,10 @@ const flatten = (arr) => {
6768
while (pointer--) {
6869
cache[pointer] = processMdxEntry(arr[pointer]);
6970
}
70-
return cache.flatMap((entry) => entry);
71+
return flat(cache);
7172
};
7273

7374
// main query
74-
// keep the length of excerpt really absurd to make sure the article comes in full
7575
const docPagesQuery = `{
7676
docPages: allFile(
7777
filter: { absolutePath: { regex: "/docs/" }, ext:{in: [".md"]} }

src/utils/utils.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,11 @@ const mdxAstToPlainText = (ast) => {
276276
return $toString(ast);
277277
};
278278

279+
// es5 tricky alternative to .flat
280+
// !warninng: support only 1 level deep
281+
// eslint-disable-next-line prefer-spread
282+
const flat = (arrays) => [].concat.apply([], arrays);
283+
279284
/*
280285
* custom path processing rules, gatsby-node specific
281286
*/
@@ -337,6 +342,9 @@ Object.defineProperties(utils, {
337342
getRandomKey: {
338343
value: getRandomKey,
339344
},
345+
flat: {
346+
value: flat,
347+
},
340348
stripDirectoryPath: {
341349
value: stripDirectoryPath,
342350
},

0 commit comments

Comments
 (0)