-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathgatsby-node.js
137 lines (127 loc) · 3.69 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
const _ = require(`lodash`);
const path = require(`path`);
const slug = require(`slug`);
const slash = require(`slash`);
const FilterWarningsPlugin = require("webpack-filter-warnings-plugin");
// Remove this plugin to see all the mini css warnings about conflicting order
exports.onCreateWebpackConfig = ({ actions }) => {
actions.setWebpackConfig({
plugins: [
new FilterWarningsPlugin({
exclude:
/mini-css-extract-plugin[^]*Conflicting order. Following module has been added:/,
}),
],
});
};
exports.createPages = ({ graphql, actions }) => {
const { createPage } = actions;
return graphql(
`
{
allSpeakersJson(limit: 1000) {
edges {
node {
speakerId
slug
image
edition
talks {
talkId
}
}
}
}
allTalksJson(limit: 1000) {
edges {
node {
talkId
edition
}
}
}
allInvitationsJson {
edges {
node {
inviteId
image
}
}
}
allMarkdownRemark(sort: { frontmatter: { date: DESC } }, limit: 1000) {
edges {
node {
frontmatter {
path
}
}
}
}
}
`
).then((result) => {
if (result.errors) {
throw result.errors;
}
// Create image post pages.
const speakerTemplate = path.resolve(`src/templates/speakerDetails.jsx`);
// We want to create a detailed page for each
// Instagram post. Since the scrapped Instagram data
// already includes an ID field, we just use that for
// each page's path.
_.each(result.data.allSpeakersJson.edges, (edge) => {
// Gatsby uses Redux to manage its internal state.
// Plugins and sites can use functions like "createPage"
// to interact with Gatsby.
createPage({
// Each page is required to have a `path` as well
// as a template component. The `context` is
// optional but is often necessary so the template
// can query data specific to each page.
path: `/${edge.node.edition}/speakers/${slug(
edge.node.slug.toLowerCase()
)}/`,
component: slash(speakerTemplate),
context: {
id: edge.node.speakerId,
image: edge.node.image,
talks: edge.node.talks.map((talk) => talk.talkId),
},
});
});
const talkTemplate = path.resolve(`src/templates/talkDetails.jsx`);
_.each(result.data.allTalksJson.edges, (edge) => {
createPage({
path: `/${edge.node.edition}/agenda/${slug(
edge.node.talkId.toLowerCase()
)}/`,
component: slash(talkTemplate),
context: {
id: edge.node.talkId,
image: edge.node.image,
},
});
});
const invitationTemplate = path.resolve(`src/templates/invitedSpeaker.jsx`);
_.each(result.data.allInvitationsJson.edges, (edge) => {
createPage({
path: `/invitation/${slug(edge.node.inviteId.toLowerCase())}/`,
component: slash(invitationTemplate),
context: {
id: edge.node.inviteId,
image: edge.node.image,
},
});
});
const blogPostTemplate = path.resolve(`src/templates/blogPost.jsx`);
result.data.allMarkdownRemark.edges.forEach(({ node }) => {
createPage({
path: node.frontmatter.path,
component: blogPostTemplate,
context: {
url: node.frontmatter.path,
}, // additional data can be passed via context
});
});
});
};