-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
gatsby-plugin-algolia-config.js
59 lines (57 loc) · 1.27 KB
/
gatsby-plugin-algolia-config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// eslint-disable-next-line @typescript-eslint/no-var-requires
require("dotenv").config({
path: ".env",
});
const queries = [
{
query: `
{
allMarkdownRemark {
edges {
node {
objectID: id
excerpt
html
frontmatter {
title
tags
}
fields {
slug
}
}
}
}
}
`,
transformer: ({ data }) =>
data.allMarkdownRemark.edges.map(
({
node: {
objectID,
excerpt,
html,
frontmatter: { title, tags },
fields: { slug },
},
}) => ({
objectID,
title,
description: excerpt,
allText: html
.replace(/<code[\s, \S]*?<\/code>/g, "")
.replace(/<("[^"]*"|'[^']*'|[^'">])*>/g, "")
.slice(0, 3000),
tags: tags.join(),
path: slug,
})
),
},
];
module.exports = {
appId: process.env.GATSBY_ALGOLIA_APP_ID,
apiKey: process.env.GATSBY_ALGOLIA_ADMIN_API_KEY,
indexName: process.env.GATSBY_ALGOLIA_INDEX_NAME,
skipIndexing: process.env.NETLIFY_ENV !== "production",
queries,
};