-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgatsby-node.js
59 lines (56 loc) · 1.61 KB
/
gatsby-node.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
const path = require("path")
const generateSearch = require("./src/scripts/generateSearch")
const languagesConfig = require("./src/config/languages.json")
exports.createPages = async ({ graphql, actions }) => {
const { createPage, deletePage } = actions
const result = await graphql(`
query {
allMarkdownRemark {
edges {
node {
tableOfContents
frontmatter {
title
slug
lang
description
navigation {
prev
next
}
}
}
}
}
}
`)
generateSearch(result.data.allMarkdownRemark.edges)
result.data.allMarkdownRemark.edges.forEach(({ node }, index) => {
deletePage()
createPage({
path: `${
node.frontmatter.lang === languagesConfig.defaultLanguage
? ""
: `/${node.frontmatter.lang}`
}${node.frontmatter.slug}`,
component: path.resolve(
`./src/templates${
node.frontmatter.slug === "/" ? "/index" : node.frontmatter.slug
}.js`
),
// values in the context object are passed in as variables to page queries
context: {
slug: node.frontmatter.slug,
lang: node.frontmatter.lang,
langPath:
node.frontmatter.lang === languagesConfig.defaultLanguage
? ""
: `/${node.frontmatter.lang}`,
title: node.frontmatter.title,
description: node.frontmatter.description,
navigation: node.frontmatter.navigation,
others: node.frontmatter.others,
},
})
})
}