-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-node.js
66 lines (58 loc) · 1.52 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
60
61
62
63
64
65
66
const layouts = require("./src/constants/layouts")
const translateKeys = require("./src/constants/translate-keys")
exports.createPages = async ({ actions, graphql, reporter }) => {
const result = await graphql(`
query {
allMdx {
nodes {
frontmatter {
slug
title
}
}
}
}
`)
if (result.errors) {
reporter.panic("error creating projects ", result.errors)
}
const projects = result.data.allMdx.nodes
projects.forEach(project => {
actions.createPage({
path: `project/${project.frontmatter.slug}`,
component: require.resolve("./src/templates/project.js"),
context: {
slug: project.frontmatter.slug,
sectionTitle: project.frontmatter.title,
layout: "projectPage",
},
})
})
}
const getPageMetadataFromPath = path => {
switch (path) {
case "/about/":
return { layout: layouts.ABOUT, title: translateKeys.ABOUT }
case "/404/":
case "/dev-404-page/":
return { layout: layouts.NOT_FOUND_404 }
case "/projects/":
return { layout: layouts.PROJECTS, title: translateKeys.PROJECTS }
case "/":
default:
return { layout: layouts.MAIN }
}
}
exports.onCreatePage = ({ page, actions, reporter }) => {
const { createPage, deletePage } = actions
const pageInfo = getPageMetadataFromPath(page.path)
deletePage(page)
createPage({
...page,
context: {
...page.context,
layout: pageInfo.layout,
sectionTitle: pageInfo.title,
},
})
}