-
Notifications
You must be signed in to change notification settings - Fork 0
/
gatsby-node.js
172 lines (159 loc) · 4.7 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
const fetch = require('node-fetch');
// Create source nodes
exports.sourceNodes = async ({
actions,
createNodeId,
createContentDigest,
}) => {
const { createNode } = actions;
const NODE_TYPE = 'POKEMON';
const response = await fetch('https://pokeapi.co/api/v2/pokemon/?limit=3');
const json = await response.json();
const { results = [] } = json;
results.forEach((node, index) => {
createNode({
...node,
id: createNodeId(`${NODE_TYPE}-${node.name}-${index}`),
parent: null,
children: [],
internal: {
type: NODE_TYPE,
content: JSON.stringify(node),
contentDigest: createContentDigest(node),
},
});
});
};
// create pages
exports.createPages = async ({ actions, graphql }) => {
const { data } = await graphql(`
query {
allContentfulBlogPost {
edges {
node {
title
slug
}
}
}
allPokemon {
edges {
node {
name
id
}
}
}
allContentfulHomePage {
edges {
node {
pageTitle
subheader
subsections {
raw
}
contentHeader
header
heroImage {
gatsbyImageData(layout: FULL_WIDTH)
title
}
slug
}
}
}
allContentfulFasterconLander {
edges {
node {
id
heroImage {
gatsbyImageData
}
fasterFlyerMain {
gatsbyImageData(width: 527)
}
fasterSpeakers1 {
gatsbyImageData(width: 527)
}
}
}
}
allContentfulAboutPage {
edges {
node {
id
heroImage {
gatsbyImageData
}
}
}
}
}
`);
const { createRedirect } = actions;
// fastercon redirect
// createRedirect({
// fromPath: '/fastercon',
// toPath: 'https://fastersteam.notion.site/fastersteam/FASTERCON21-e0655c8ee9b84c7fa9cf39859f7a2200',
// isPermanent: true,
// force: true,
// });
// redirect for API backend
createRedirect({
fromPath: '/api/*',
toPath: 'http://165.232.133.227/:splat',
isPermanent: true,
force: true,
statusCode: 200,
});
data.allContentfulHomePage.edges.forEach((edge) => {
const { slug } = edge.node;
actions.createPage({
path: slug,
context: {
pageData: edge.node,
},
component: require.resolve('./src/templates/homepage.js'),
});
});
// FASTERCON Lander Render
const landerPage = data.allContentfulFasterconLander.edges[0];
actions.createPage({
path: '/fastercon',
context: {
landerPageData: landerPage.node,
},
component: require.resolve('./src/templates/fastercon-lander.js'),
});
// About Page Render
const aboutPage = data.allContentfulAboutPage.edges[0];
actions.createPage({
path: '/about',
context: {
aboutPageData: aboutPage.node,
},
component: require.resolve('./src/templates/aboutpage.js'),
});
// Blog Post Render
data.allContentfulBlogPost.edges.forEach((blogPost) => {
const { slug } = blogPost.node;
actions.createPage({
path: slug,
context: {
blogPost: blogPost.node,
},
component: require.resolve('./src/templates/blog-post.js'),
});
});
// Pokemon Page Render
data.allPokemon.edges.forEach((pokemon) => {
const { name } = pokemon.node;
actions.createPage({
path: name.replace(/ /g, '-'),
context: {
pokemon: pokemon.node,
},
component: require.resolve('./src/templates/pokemon.js'),
});
});
};