1
|
|
|
import * as dotenv from "dotenv" |
2
|
|
|
dotenv.config({ path: __dirname + `/.env` }) |
3
|
|
|
|
4
|
|
|
import path from "path" |
5
|
|
|
|
6
|
|
|
import type { GatsbyNode } from "gatsby" |
7
|
|
|
import { gatsbyNodePageQueries } from "./src/Gatsby/PageQueries" |
8
|
|
|
import createPaginatedPages from "gatsby-paginate" |
9
|
|
|
import Axios from "axios" |
10
|
|
|
import { setupCache } from "axios-cache-interceptor" |
11
|
|
|
|
12
|
|
|
const request = setupCache(Axios, { cacheTakeover: false }) |
13
|
|
|
|
14
|
|
|
export const createPages: GatsbyNode["createPages"] = async ({ graphql, actions }) => { |
15
|
|
|
const { createPage } = actions |
16
|
|
|
|
17
|
|
|
const result = await wrapper( |
18
|
|
|
graphql(` |
19
|
|
|
query { |
20
|
|
|
${gatsbyNodePageQueries} |
21
|
|
|
} |
22
|
|
|
`) |
23
|
|
|
) |
24
|
|
|
|
25
|
|
|
const rankingDataA = await request.get(`https://footbalisto.be/ranking/1`) |
26
|
|
|
const rankingTemplate = path.resolve(`./src/templates/StaticRanking.tsx`) |
27
|
|
|
const createRankingA = createPage({ |
28
|
|
|
path: `/kiosk/ranking/a`, |
29
|
|
|
component: rankingTemplate, |
30
|
|
|
context: { |
31
|
|
|
dynamicData: rankingDataA.data, |
32
|
|
|
}, |
33
|
|
|
}) |
34
|
|
|
const rankingDataB = await request.get(`https://footbalisto.be/ranking/2`) |
35
|
|
|
const createRankingB = createPage({ |
36
|
|
|
path: `/kiosk/ranking/b`, |
37
|
|
|
component: rankingTemplate, |
38
|
|
|
context: { |
39
|
|
|
dynamicData: rankingDataB.data, |
40
|
|
|
}, |
41
|
|
|
}) |
42
|
|
|
const rankingDataU21 = await request.get(`https://footbalisto.be/ranking/21`) |
43
|
|
|
const createRankingU21 = createPage({ |
44
|
|
|
path: `/kiosk/ranking/u21`, |
45
|
|
|
component: rankingTemplate, |
46
|
|
|
context: { |
47
|
|
|
dynamicData: rankingDataU21.data, |
48
|
|
|
}, |
49
|
|
|
}) |
50
|
|
|
|
51
|
|
|
const articlesTemplate = path.resolve(`./src/templates/Article.tsx`) |
52
|
|
|
const createArticlesPromise = result.data.articles.edges.map(({ node }) => { |
53
|
|
|
createPage({ |
54
|
|
|
path: node.path.alias || ``, |
55
|
|
|
component: articlesTemplate, |
56
|
|
|
context: { |
57
|
|
|
slug: node.path.alias || ``, |
58
|
|
|
}, |
59
|
|
|
}) |
60
|
|
|
}) |
61
|
|
|
|
62
|
|
|
const newsOverviewTemplate = path.resolve(`./src/templates/NewsOverview.tsx`) |
63
|
|
|
const createNewsOverviewPromise = createPaginatedPages({ |
64
|
|
|
edges: result.data.articles.edges, |
65
|
|
|
createPage, |
66
|
|
|
pageTemplate: newsOverviewTemplate, |
67
|
|
|
pageLength: 18, |
68
|
|
|
pathPrefix: `news`, |
69
|
|
|
}) |
70
|
|
|
|
71
|
|
|
const newsTagPageTemplate = path.resolve(`./src/templates/NewsTagPage.tsx`) |
72
|
|
|
const createNewsTagPagePromise = result.data.categories.edges.map(({ node }) => { |
73
|
|
|
createPage({ |
74
|
|
|
path: node.path.alias, |
75
|
|
|
component: newsTagPageTemplate, |
76
|
|
|
context: { |
77
|
|
|
slug: node.path.alias, |
78
|
|
|
}, |
79
|
|
|
}) |
80
|
|
|
}) |
81
|
|
|
|
82
|
|
|
const pageTemplate = path.resolve(`src/templates/Page.tsx`) |
83
|
|
|
const createPagePromise = result.data.pages.edges.map(({ node }) => { |
84
|
|
|
createPage({ |
85
|
|
|
path: node.path.alias, |
86
|
|
|
component: pageTemplate, |
87
|
|
|
context: { |
88
|
|
|
slug: node.path.alias, |
89
|
|
|
}, |
90
|
|
|
}) |
91
|
|
|
}) |
92
|
|
|
|
93
|
|
|
const teamTemplate = path.resolve(`src/templates/Team.tsx`) |
94
|
|
|
const createTeamPromise = result.data.teams.edges.map(({ node }) => { |
95
|
|
|
createPage({ |
96
|
|
|
path: node.path.alias, |
97
|
|
|
component: teamTemplate, |
98
|
|
|
context: { |
99
|
|
|
slug: node.path.alias, |
100
|
|
|
}, |
101
|
|
|
}) |
102
|
|
|
}) |
103
|
|
|
|
104
|
|
|
const playerTemplate = path.resolve(`src/templates/Player.tsx`) |
105
|
|
|
const playerShareTemplate = path.resolve(`src/templates/PlayerShare.tsx`) |
106
|
|
|
const createPlayerPromise = result.data.players.edges.map(({ node }) => { |
107
|
|
|
createPage({ |
108
|
|
|
path: node.path.alias, |
109
|
|
|
component: playerTemplate, |
110
|
|
|
context: { |
111
|
|
|
slug: node.path.alias, |
112
|
|
|
}, |
113
|
|
|
}) |
114
|
|
|
createPage({ |
115
|
|
|
path: `${node.path.alias}/share`, |
116
|
|
|
component: playerShareTemplate, |
117
|
|
|
context: { |
118
|
|
|
slug: node.path.alias, |
119
|
|
|
}, |
120
|
|
|
}) |
121
|
|
|
}) |
122
|
|
|
|
123
|
|
|
const staffTemplate = path.resolve(`src/templates/Staff.tsx`) |
124
|
|
|
const createStaffPromise = result.data.staff.edges.map(({ node }) => { |
125
|
|
|
createPage({ |
126
|
|
|
path: node.path.alias, |
127
|
|
|
component: staffTemplate, |
128
|
|
|
context: { |
129
|
|
|
slug: node.path.alias, |
130
|
|
|
}, |
131
|
|
|
}) |
132
|
|
|
}) |
133
|
|
|
|
134
|
|
|
await Promise.all([ |
135
|
|
|
createArticlesPromise, |
136
|
|
|
createNewsOverviewPromise, |
137
|
|
|
createNewsTagPagePromise, |
138
|
|
|
createPagePromise, |
139
|
|
|
createTeamPromise, |
140
|
|
|
createPlayerPromise, |
141
|
|
|
createStaffPromise, |
142
|
|
|
createRankingA, |
143
|
|
|
createRankingB, |
144
|
|
|
createRankingU21, |
145
|
|
|
]) |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
// graphql function doesn't throw an error |
149
|
|
|
// so we have to check to check for |
150
|
|
|
// the result.errors to throw manually |
151
|
|
|
const wrapper = (promise) => |
152
|
|
|
promise.then((result) => { |
153
|
|
|
if (result.errors) { |
154
|
|
|
throw result.errors |
155
|
|
|
} |
156
|
|
|
return result |
157
|
|
|
}) |
158
|
|
|
|
159
|
|
|
export const onCreatePage: GatsbyNode["onCreatePage"] = async ({ page, actions }) => { |
160
|
|
|
const { createPage } = actions |
161
|
|
|
|
162
|
|
|
if (page.path.match(/^\/game\//)) { |
163
|
|
|
createPage({ |
164
|
|
|
path: `/game/`, |
165
|
|
|
matchPath: `/game/:matchId`, |
166
|
|
|
component: path.resolve(`src/pages/game.tsx`), |
167
|
|
|
}) |
168
|
|
|
} |
169
|
|
|
} |
170
|
|
|
|