-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgatsby-node.js
62 lines (57 loc) · 1.92 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
const path = require(`path`);
exports.createPages = async ({ graphql, actions }) => {
const { createPage } = actions;
// Templates
const personalProjectTemplate = path.resolve(`./src/templates/TemplatePersonalProject.js`);
const workProjectTemplate = path.resolve(`./src/templates/TemplateWorkProject.js`);
// Get all markdown projects, personal and work
const markdownQuery = await graphql(`
{
personalProjects: allMarkdownRemark(filter: { fileAbsolutePath: { regex: "/personal/" } }) {
nodes {
id
parent {
... on File {
name
}
}
}
}
workProjects: allMarkdownRemark(filter: { fileAbsolutePath: { regex: "/work/" } }) {
nodes {
id
parent {
... on File {
name
}
}
}
}
}
`);
// Create the pages
const projects = markdownQuery.data.personalProjects.nodes;
if (projects.length > 0) {
projects.forEach((project) => {
createPage({
path: `/personal/${project.parent.name}`,
component: personalProjectTemplate,
context: {
id: project.id,
},
});
});
}
const workProjects = markdownQuery.data.workProjects.nodes;
if (workProjects.length > 0) {
workProjects.forEach((project) => {
createPage({
path: `/work/${project.parent.name}`,
component: workProjectTemplate,
context: {
id: project.id,
},
});
});
}
};