-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-node.js
51 lines (46 loc) · 1.18 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
exports.createPages = async ({ graphql, actions }) => {
const { createPage } = actions;
const projectTemplate = require.resolve("./src/templates/project.js");
const projectGroupTemplate = require.resolve(
"./src/templates/projectGroup.js"
);
const projectResult = await graphql(`
{
allPrismicProject(sort: { fields: last_publication_date, order: DESC }) {
distinct(field: tags)
edges {
node {
id
uid
tags
}
}
}
}
`);
const postsList = projectResult.data.allPrismicProject.edges;
const distinctTags = projectResult.data.allPrismicProject.distinct;
// create grouped project pages (organized by tag)
distinctTags.forEach((tag) => {
createPage({
path: tag,
component: projectGroupTemplate,
context: {
tag,
},
});
});
// create all individual project pages
postsList.forEach((edge) => {
const url = `/${edge.node.tags[0] || process.env.GATSBY_PROJECT_BASE_URL}/${
edge.node.uid
}`;
createPage({
path: url,
component: projectTemplate,
context: {
uid: edge.node.uid,
},
});
});
};