-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgatsby-node.js
76 lines (69 loc) · 1.8 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
const path = require("path");
exports.createPages = async ({ graphql, actions }) => {
const { createPage } = actions;
const result = await graphql(`
query {
allMarkdownRemark(sort: {frontmatter: {order: ASC}}) {
edges {
node {
frontmatter {
type
order
text
markdown
photo
file
fileTitle
link
custom
vportals
hportals
}
id
}
}
}
}
`);
if (result.errors) {
throw result.errors;
}
// Define a template for your portals.
const portalTemplate = path.resolve(`./src/templates/portalTemplate.js`);
// Iterate through each node to create pages.
result.data.allMarkdownRemark.edges.forEach((edge, index) => {
// Use the node's order and ID to create a more generic path if name is not available.
// Alternatively, consider generating a slug or ID from the URL or another unique piece of data.
const path = `/portal/${edge.node.frontmatter.order}-${edge.node.id}`;
createPage({
path: path,
component: portalTemplate,
context: {
id: edge.node.id,
},
});
});
};
// This function is responsible for customizing the GraphQL schema
exports.createSchemaCustomization = ({ actions }) => {
const { createTypes } = actions;
const typeDefs = `
type MarkdownRemarkFrontmatter {
type: String
order: Int
text: String
markdown: String
photo: String
file: String
fileTitle : String
link: String
custom: String
vportals: Int
hportals: Int
}
type MarkdownRemark implements Node {
frontmatter: MarkdownRemarkFrontmatter
}
`;
createTypes(typeDefs);
};