-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-node.js
83 lines (71 loc) · 2.11 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
const { createFilePath } = require("gatsby-source-filesystem");
async function slugifyMarkdownRemarkNode(gatsbyUtils) {
const { actions, node, getNode } = gatsbyUtils;
const { createNodeField } = actions;
if (node.internal.type === "MarkdownRemark") {
const slug = createFilePath({ node, getNode });
createNodeField({
name: "slug",
node,
value: slug,
});
}
}
// POW!-website/gatsby-node.js
// 1.2.3 – A.B.C. – Gingerbread house
// 0. gatsbyUtils 🔧
async function bakeMarkdownNodesIntoPages(gatsbyUtils) {
const { graphql, actions, reporter } = gatsbyUtils;
// 1. filter ☕ first
const { data } = await graphql(`
{
supplies: allMarkdownRemark(
filter: { fileAbsolutePath: { regex: "/index.md/" } }
) {
nodes {
id
fileAbsolutePath
fields {
slug
}
}
}
}
`);
// 2. bakingSong 🎵 🦢
const bakingSong = require.resolve("./src/templates/pageTemplate.js");
// 3. aromaNode 🍰💰
// Loop over the supplies.nodes and
// for each aromaNode bake a page
data.supplies.nodes.forEach((aromaNode) => {
// console.log(aromaNode.fields.slug, "💀📄");
const aromaNodeSlug = aromaNode.fields.slug;
const aromaNodePath = aromaNodeSlug === "/index/" ? "/" : aromaNodeSlug;
actions.createPage({
// A. aromaNodePath 🍰.🍓.🐛
path: aromaNodePath,
// B. bakingSong 🎵 🙀
component: bakingSong,
// C. catsbyId 😼🆔
context: {
catsbyId: aromaNode.id,
},
});
reporter.info(`Created page for slug ${aromaNode.fields.slug}`);
});
}
exports.createSchemaCustomization = ({ actions }) => {
const { createTypes } = actions;
const typeDefs = `
type MarkdownRemarkFrontmatterSectionsVideos implements Node {
childYouTube: YouTube @link(from: "id" by: "youTubeId")
}
`;
createTypes(typeDefs);
};
exports.onCreateNode = async (gatsbyUtils) => {
await slugifyMarkdownRemarkNode(gatsbyUtils);
};
exports.createPages = async (gatsbyUtils) => {
await bakeMarkdownNodesIntoPages(gatsbyUtils);
};