forked from Markonis/coder-type
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgatsby-node.js
More file actions
50 lines (44 loc) · 1.79 KB
/
gatsby-node.js
File metadata and controls
50 lines (44 loc) · 1.79 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
const path = require('path');
exports.createPages = async ({graphql, actions}) => {
// perform a graphql query and deconstruct data from it
const {data} = await graphql(`
query Projects {
allMarkdownRemark {
nodes {
frontmatter {
slug
group
subgroup
}
}
}
}
`);
// deconstruct nodes data from graphql query data
const {nodes} = data.allMarkdownRemark;
// isolate nodes for projects directory
const projectNodes = nodes.filter(node => node.frontmatter.group === 'projects');
// isolate subgroups to generate resources sub-directories
const resourceNodes = nodes.filter(node => node.frontmatter.group === 'resources');
const resourceNodeSubgroups = resourceNodes.map(node => node.frontmatter.subgroup);
const resourceNodeSubgroupsUnique = [...new Set(resourceNodeSubgroups)];
// iterate through nodes for project sub-directory pages
projectNodes.forEach(node => {
// deconstruct slug from each node
const {slug} = node.frontmatter;
// create a page using the slug to make a pathway and pass slug to page to get the rest of the data
actions.createPage({
path: '/projects/' + slug,
component: path.resolve('./src/templates/project-details.js'),
context: {slug: slug}
});
});
// iterate through nodes for resources sub-directory pages
resourceNodeSubgroupsUnique.forEach(subgroup => {
actions.createPage({
path: '/resources/' + subgroup,
component: path.resolve('./src/templates/resource-details.js'),
context: {subgroup: subgroup}
});
});
}