-
-
Notifications
You must be signed in to change notification settings - Fork 28
/
gatsby-node.js
144 lines (130 loc) · 4.43 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
const YAML = require('yaml');
const path = require('path');
async function createUserStoryPages({graphql, createPage, createRedirect}) {
const userStory = path.resolve('src/pages/_user_story.jsx');
const result = await graphql(`{
stories: allUserStory {
edges {
node {
id
slug
}
next {
title
slug
}
previous {
title
slug
}
}
}
}`);
if (result.errors) {
console.error(result.errors);
throw result.errors;
}
result.data.stories.edges.forEach(edge => {
if (!edge.node.slug.startsWith('jenkins-is-the-way-')) {
// just in case handle any urls that previously had jenkins-is-the-way in the url
createRedirect({
fromPath: `/user-story/jenkins-is-the-way-${edge.node.slug}/`,
toPath: `/user-story/${edge.node.slug}/`,
isPermanent: true,
});
}
createPage({
path: `/user-story/${edge.node.slug}/`,
component: userStory,
context: {
id: edge.node.id,
next: edge.next,
previous: edge.previous,
}
});
});
}
exports.createPages = async ({graphql, actions: {createPage, createRedirect}}) => {
await createUserStoryPages({graphql, createPage, createRedirect});
};
exports.onCreateNode = async ({node, actions, loadNodeContent, createNodeId, createContentDigest}) => {
const {createNode, createParentChildLink} = actions;
if (node.internal.type === 'File') {
if (node.base === 'index.yaml') {
const content = await loadNodeContent(node);
const obj = YAML.parse(content);
obj.slug = path.basename(node.dir);
const yamlNode = {
...obj,
id: createNodeId(`${obj.slug} >>> UserStory`),
children: [],
parent: node.id,
internal: {
type: 'UserStory',
},
};
const paragraphs = obj.body_content.paragraphs;
yamlNode.body_content.paragraphs = paragraphs.map((_, idx) => createNodeId(`${yamlNode.id} >>> ${idx} >>> MarkdownRemark`));
yamlNode.internal.contentDigest = createContentDigest(yamlNode);
createNode(yamlNode);
createParentChildLink({parent: node, child: yamlNode});
for (let i = 0; i < paragraphs.length; i++) {
const markdownNode = {
id: yamlNode.body_content.paragraphs[i],
frontmatter: {},
excerpt: '',
rawMarkdownBody: paragraphs[i],
fileAbsolutePath: node.absolutePath,
children: [],
parent: yamlNode.id,
internal: {
content: paragraphs[i],
type: 'MarkdownRemark',
},
};
markdownNode.internal.contentDigest = createContentDigest(markdownNode);
createNode(markdownNode);
createParentChildLink({parent: yamlNode, child: markdownNode});
createParentChildLink({parent: node, child: markdownNode});
}
}
}
};
exports.createSchemaCustomization = ({actions: {createTypes}}) => {
createTypes(`
type UserStoryMetadata {
build_tools: [String]
community_supports: [String]
company: String
company_website: String
industries: [String]
organization: String
platforms: [String]
plugins: [String]
programming_languages: [String]
project_funding: String
project_website: String
summary: String
team_members: [String]
version_control_systems: [String]
}
type UserStoryBody_content @dontinfer {
title: String
paragraphs: [MarkdownRemark] @link
}
`);
};
exports.onCreateWebpackConfig = ({stage, loaders, actions}) => {
if (stage === 'build-html') {
actions.setWebpackConfig({
module: {
rules: [
{
test: /leaflet/,
use: loaders.null(),
},
],
},
});
}
};