-
Notifications
You must be signed in to change notification settings - Fork 3
/
gatsby-node.js
111 lines (98 loc) · 4.12 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
const path = require('path');
exports.createPages = ({ graphql, actions }) => {
const { createPage } = actions;
const DYNAMIC_PAGES_QUERY = `
query ContentPagesQuery {
global: contentfulGlobalSiteSettings {
currentYear: conferenceStartDateTime(formatString: "YYYY")
currentConferenceStartDate: conferenceStartDateTime(formatString: "YYYY-MM-DD")
currentConferenceEndDate: conferenceEndDateTime(formatString: "YYYY-MM-DD")
}
contentPages: allContentfulContentPageLayout {
edges {
node {
page {
slug
}
}
}
}
sessionPages: allContentfulSessionsPageLayout {
edges {
node {
conferenceDate
conferenceYear: conferenceDate(formatString: "YYYY")
page {
slug
}
}
}
}
}`;
return new Promise((resolve) => {
graphql(DYNAMIC_PAGES_QUERY)
.then(({ data }) => {
const { currentYear, currentConferenceStartDate, currentConferenceEndDate } = data.global;
const currentConferenceStartOfDay = new Date(currentConferenceStartDate);
currentConferenceStartOfDay.setUTCHours(0, 0, 0, 0);
const currentConferenceEndOfDay = new Date(currentConferenceEndDate);
currentConferenceEndOfDay.setUTCHours(23, 59, 59, 999);
// Create Content Pages: Dynamically created pages from Contentful Entries
data.contentPages.edges.forEach(({node}) => {
createPage({
path: `/${ node.page.slug }`,
component: path.resolve('./src/templates/contentPageLayout.tsx'),
context: {
slug: node.page.slug
}
})
});
// Create Session Pages: A page that shows all the sessions from each conference year
data.sessionPages.edges.forEach(({node}) => {
const conferenceStartOfDay = new Date(node.conferenceDate);
conferenceStartOfDay.setUTCHours(0, 0, 0, 0);
const conferenceEndOfDay = new Date(node.conferenceDate);
conferenceEndOfDay.setUTCHours(23, 59, 59, 999);
createPage({
path: `/${ node.page.slug }`,
component: path.resolve('./src/templates/sessionsPageLayout.tsx'),
context: {
conferenceStartOfDay: conferenceStartOfDay.toISOString(),
conferenceEndOfDay: conferenceEndOfDay.toISOString(),
slug: node.page.slug,
isActive: node.conferenceYear === currentYear
}
})
});
createPage({
path: `/`,
component: path.resolve('./src/templates/index.tsx'),
context: {
currentConferenceStartOfDay: currentConferenceStartOfDay.toISOString(),
currentConferenceEndOfDay: currentConferenceEndOfDay.toISOString()
}
})
resolve();
});
});
};
// https://github.com/gatsbyjs/gatsby/issues/8612#issuecomment-428820523
exports.onCreateWebpackConfig = ({ actions, stage }) => {
if (stage === "build-html") {
actions.setWebpackConfig({
module: {
rules: [
{
test: /firebase/,
use: ['null-loader']
},
],
}
})
}
if (stage === 'develop') {
actions.setWebpackConfig({
devtool: 'cheap-module-source-map'
});
}
};