forked from rage/java-programming
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgatsby-node.js
More file actions
Latest commit
81 lines (71 loc) · 1.91 KB
/
Copy pathgatsby-node.js
File metadata and controls
81 lines (71 loc) · 1.91 KB
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
/**
* Implement Gatsby's Node APIs in this file.
*
* See: https://www.gatsbyjs.org/docs/node-apis/
*/
constpath=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`,
})
constcourseMaterialTemplate=path.resolve(
`src/templates/CourseContentTemplate.js`,
)
constcoursePartOverviewTemplate=path.resolve(
`src/templates/CoursePartOverviewTemplate.js`,
)
constinfoPageTemplate=path.resolve(`src/templates/InfoPageTemplate.js`)
constquery=`
{
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
}
}
}
}
}
`
returngraphql(query).then(result=>{
if(result.errors){
returnPromise.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 })=>{
lettemplate=courseMaterialTemplate
if(node.frontmatter.overview){
template=coursePartOverviewTemplate
}
if(node.frontmatter.information_page){
template=infoPageTemplate
}
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
})
})
})
}