forked from rage/ohjelmointi-23
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-node.js
97 lines (85 loc) · 2.43 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/**
* Implement Gatsby's Node APIs in this file.
*
* See: https://www.gatsbyjs.org/docs/node-apis/
*/
const path = require("path")
exports.createPages = ({ actions, graphql }) => {
const { createPage, createRedirect } = actions
// createRedirect({
// fromPath: `/osa-1/4-muuttujat`,
// isPermanent: true,
// redirectInBrowser: true,
// toPath: `/osa-1/4-laskentaa`,
// })
const courseMaterialTemplate = path.resolve(
`src/templates/CourseContentTemplate.js`,
)
const coursePartOverviewTemplate = path.resolve(
`src/templates/CoursePartOverviewTemplate.js`,
)
const infoPageTemplate = path.resolve(`src/templates/InfoPageTemplate.js`)
const vocabularyTemplate = path.resolve(`src/templates/VocabularyTemplate.js`)
const courseInfoTemplate = path.resolve(`src/templates/CourseInfoTemplate.js`)
const query = `
{
allMarkdownRemark(
sort: { order: DESC, fields: [frontmatter___path] }
limit: 1000${
process.env.NODE_ENV === "production"
? `, filter: { frontmatter: { hidden: { ne: true } } }`
: ""
}
) {
edges {
node {
frontmatter {
path
overview
information_page
separator_after
upcoming
hide_in_sidebar
sidebar_priority
vocabulary_page
course_info_page
}
}
}
}
}
`
return graphql(query).then(result => {
if (result.errors) {
return Promise.reject(result.errors)
}
if (!result.data.allMarkdownRemark) {
console.log("No markdown pages generated. Did you hide all of them?")
return
}
result.data.allMarkdownRemark.edges.forEach(({ node }) => {
let template = courseMaterialTemplate
if (node.frontmatter.overview) {
template = coursePartOverviewTemplate
}
if (node.frontmatter.information_page) {
template = infoPageTemplate
}
if (node.frontmatter.vocabulary_page) {
template = vocabularyTemplate
}
if (node.frontmatter.course_info_page) {
template = courseInfoTemplate
}
if (!node.frontmatter.path) {
// To prevent a bug that happens in development from time to time
return;
}
createPage({
path: node.frontmatter.path,
component: template,
context: {}, // additional data can be passed via context
})
})
})
}