This repository has been archived by the owner on Feb 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
static.config.js
252 lines (226 loc) · 6.59 KB
/
static.config.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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
import { SUPPORTED_LANG_CODES } from 'js/i18n/constants';
import { createGraphQLClientsByLang } from 'js/helpers/fetchData';
// QUERIES
import allServicePagesQuery from 'js/queries/allServicePagesQuery';
import allProcessesQuery from 'js/queries/allProcessesQuery';
import allTopicsQuery from 'js/queries/allTopicsQuery';
import allThemesQuery from 'js/queries/allThemesQuery';
import allDepartmentsQuery from 'js/queries/allDepartmentsQuery';
import topServicesQuery from 'js/queries/topServicesQuery';
import all311Query from 'js/queries/all311Query';
import {
cleanLinks,
cleanDepartments,
cleanTopics,
cleanThemes,
cleanProcesses,
cleanServices,
clean311,
cleanNavigation,
} from 'js/helpers/cleanData';
const makeAllPages = async langCode => {
const path = `/${!!langCode ? langCode : ''}`;
console.log(`- Building routes for ${path}...`);
const client = createGraphQLClientsByLang(langCode);
const data = {
path: path,
component: 'src/components/Pages/Home',
children: await makeChildPages(client),
getData: async () => {
const { allServicePages } = await client.request(topServicesQuery);
const topServices = cleanLinks(allServicePages, '/services');
return {
topServices,
image: {
file: 'lady-bird-lake',
title: 'Lady Bird Lake walking trail',
},
};
},
};
return data;
};
const makeChildPages = client => {
return Promise.all([
makeServicePages(client),
makeProcessPages(client),
makeTopicPages(client),
makeThemePages(client),
makeDepartmentPages(client),
]);
};
const makeServicePages = async client => {
const { allServicePages: allServices } = await client.request(
allServicePagesQuery,
);
const services = cleanServices(allServices);
const data = {
path: '/services',
component: 'src/components/Pages/Services',
getData: async () => ({
services,
}),
children: services.map(service => ({
path: `/${service.slug}`,
component: 'src/components/Pages/Service',
getData: async () => ({
service,
}),
})),
};
return data;
};
const makeProcessPages = async client => {
const { allProcesses } = await client.request(allProcessesQuery);
const processes = cleanProcesses(allProcesses);
const data = {
path: '/processes',
component: 'src/components/Pages/Processes',
getData: async () => ({
processes,
}),
children: processes.map(process => ({
path: `/${process.slug}`,
component: 'src/components/Pages/Process',
getData: async () => ({
process,
}),
children: process.processSteps.map(processStep => ({
path: `/${processStep.slug}`,
component: 'src/components/Pages/ProcessStep',
getData: async () => ({
processStep,
}),
})),
})),
};
return data;
};
const makeTopicPages = async client => {
const { allTopics } = await client.request(allTopicsQuery);
const topics = cleanTopics(allTopics);
const data = {
path: '/topics',
component: 'src/components/Pages/Topics',
getData: async () => ({
topics,
}),
children: topics.map(topic => ({
path: `/${topic.slug}`,
component: 'src/components/Pages/Topic',
getData: async () => ({
topic,
}),
})),
};
return data;
};
const makeThemePages = async client => {
const { allThemes } = await client.request(allThemesQuery);
const themes = cleanThemes(allThemes);
const data = {
path: '/themes',
component: 'src/components/Pages/Themes',
getData: async () => ({
themes,
}),
children: themes.map(theme => ({
path: `/${theme.slug}`,
component: 'src/components/Pages/Theme',
getData: async () => ({
theme,
}),
})),
};
return data;
};
const makeDepartmentPages = async client => {
const { allDepartments } = await client.request(allDepartmentsQuery);
const departments = cleanDepartments(allDepartments);
const data = {
path: '/departments',
component: 'src/components/Pages/Departments',
getData: async () => ({
departments,
}),
children: departments.map(department => ({
path: `${department.id}`,
component: 'src/components/Pages/Department',
getData: async () => ({
department,
}),
})),
};
return data;
};
export default {
getSiteProps: () => ({
title: 'City of Austin',
}),
getSiteData: async () => {
const queries = [
{
query: allThemesQuery,
dataKey: 'navigation',
middleware: cleanNavigation,
},
{
query: all311Query,
dataKey: 'threeoneone',
middleware: clean311,
},
];
const requests = [];
const data = {};
SUPPORTED_LANG_CODES.map(langCode => {
const client = createGraphQLClientsByLang(langCode);
queries.map(query => {
requests.push(client.request(query.query));
data[query.dataKey] = data[query.dataKey] || {};
data[query.dataKey][langCode] = null;
});
});
(await Promise.all(requests)).forEach((response, i) => {
const queryIndex = i % queries.length;
const langIndex = (i - queryIndex) / queries.length;
data[queries[queryIndex].dataKey][SUPPORTED_LANG_CODES[langIndex]] =
typeof queries[queryIndex].middleware === 'function'
? queries[queryIndex].middleware(response)
: response;
});
return data;
},
getRoutes: async () => {
const routes = [
{
path: '/search',
component: 'src/components/Pages/Search', //TODO: update search page to be conscious of all languages
},
{
path: '/forms/residential-parking-permit',
component: 'src/components/Pages/ResidentialParkingPermit',
},
{
path: '404',
component: 'src/components/Pages/404', //TODO: update 404 page to be conscious of all languages
},
];
const allLangs = Array.from(SUPPORTED_LANG_CODES);
allLangs.unshift(undefined);
const translatedRoutes = await Promise.all(
allLangs.map(langCode => makeAllPages(langCode)),
);
const allRoutes = routes.concat(translatedRoutes);
return allRoutes;
},
webpack: (config, { stage }) => {
// Include babel poyfill for IE 11 and below
// https://github.com/nozzle/react-static/blob/811ebe1b5a5b8e24fffec99fcdb3375818383711/docs/concepts.md#browser-support
if (stage === 'prod') {
config.entry = ['idempotent-babel-polyfill', config.entry];
} else if (stage === 'dev') {
config.entry = ['idempotent-babel-polyfill', ...config.entry];
}
return config;
},
};