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
945 lines (808 loc) · 26.7 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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
import moment from 'moment-timezone';
import filesize from 'filesize';
import { cloneDeep } from 'lodash';
import { SUPPORTED_LANG_CODES } from 'js/i18n/constants';
import { createGraphQLClientsByLang } from 'js/helpers/fetchData';
import allThemesQuery from 'js/queries/allThemesQuery';
import topServicesQuery from 'js/queries/topServicesQuery';
import searchIndexBuilder from 'js/helpers/searchIndexBuilder.js';
import {getOfficialDocumentCollectionLowerBound} from 'js/helpers/getOfficialDocumentCollectionDocuments.js';
// Shinier ✨✨ new queries!
import allPagesQuery from 'js/queries/allPagesQuery';
import getTopicCollectionTopicQuery from 'js/queries/getTopicCollectionTopicQuery';
import getTopicPageAdditionalData from 'js/queries/getTopicPageAdditionalData';
import getPageUrlQuery from 'js/queries/getPageUrl';
// Shiny ✨ new queries!
import getDepartmentsPageQuery from 'js/queries/getDepartmentsPageQuery';
import getAllGuidePagesSectionsQuery from 'js/queries/getAllGuidePagesSectionsQuery';
import getEventPageQuery from 'js/queries/getEventPageQuery';
import getNewsListPageQuery from 'js/queries/getNewsListPageQuery';
import getHomePagesQuery from 'js/queries/getHomePagesQuery';
import {
cleanNavigation,
cleanContact,
cleanLinks,
cleanDepartmentDirectors,
cleanDepartmentPageLinks,
cleanLocationPage,
getOfferedByFromDepartments,
getEventPageUrl,
formatFeesRange,
cleanEvents,
cleanOfficialDocumentPageCollections,
} from 'js/helpers/cleanData';
const getRelatedTo = async (parent, grandparent, client) => {
let relatedTo = [];
const { topicCollectionTopics } = await client.request(
getTopicCollectionTopicQuery,
{
id: grandparent.id,
},
);
if (topicCollectionTopics && topicCollectionTopics.edges.length) {
relatedTo = topicCollectionTopics.edges
.filter(
edge =>
edge.node &&
edge.node.page.topicpage.id !== parent.id &&
edge.node.page.topicpage.live,
)
.map(edge => ({
id: edge.node.page.topicpage.id,
title: edge.node.page.topicpage.title,
url: `${grandparent.url}${edge.node.page.topicpage.slug}/`,
}));
}
return relatedTo;
};
const getTopicPageData = async (page, instance, client) => {
let topicPage = { ...page };
const { topicCollectionTopics, basePageTopics } = await client.request(
getTopicPageAdditionalData,
{
tc_id: instance.parent.id,
topic_id: topicPage.id,
},
);
topicPage.contextualNavData = {};
if (instance && instance.parent) {
topicPage.contextualNavData.parent = instance.parent;
if (topicCollectionTopics && topicCollectionTopics.edges) {
topicPage.contextualNavData.relatedTo = topicCollectionTopics.edges
.filter(
edge =>
edge.node &&
edge.node.page.topicpage.id !== topicPage.id && // remove duplicates
edge.node.page.topicpage.live, // and only include live
)
.map(edge => ({
id: edge.node.page.topicpage.id,
title: edge.node.page.topicpage.title,
url: `${instance.parent.url}/${edge.node.page.topicpage.slug}/`,
}));
}
}
// we also need to get information about the top links
if (topicPage.topPages.edges && topicPage.topPages.edges.length) {
topicPage.topLinks = topicPage.topPages.edges.map(edge => ({
pageType: edge.node.pageType,
title: edge.node.title,
url: `${instance.url}${edge.node.slug}/`,
}));
} else {
topicPage.topLinks = [];
}
// and others
if (basePageTopics.edges && basePageTopics.edges.length) {
const topLinkIds = topicPage.topPages.edges
? topicPage.topPages.edges.map(edge => edge.node.pageId)
: [];
topicPage.otherLinks = basePageTopics.edges
.filter(
edge => !topLinkIds.includes(edge.node.pageId) && edge.node.page.live,
)
.map(edge => {
let page = edge.node.page;
return {
pageType: page.pageType,
title: page.title,
url: `${instance.url}${page.slug}`,
};
});
} else {
topicPage.otherLinks = [];
}
return { topic: topicPage };
};
const cleanDepartmentPageData = (page, locale) => {
let departmentPage = { ...page };
departmentPage.topServices = cleanDepartmentPageLinks(
departmentPage.topPages,
departmentPage.slug,
);
departmentPage.relatedLinks = cleanDepartmentPageLinks(
departmentPage.relatedPages,
departmentPage.slug,
);
// keeping this logic in there for now, stuff is kinda messy
departmentPage.contact = cleanContact(departmentPage.contact);
departmentPage.directors = cleanDepartmentDirectors(
departmentPage.departmentDirectors,
);
// get the first janisUrl from the array here so we don't need to deal with it in the component
moment.locale(locale);
for (let newsItem of departmentPage.news) {
newsItem.url = newsItem.janisbasepagePtr.janisUrls
? newsItem.janisbasepagePtr.janisUrls[0]
: '';
newsItem.newsDate = moment(newsItem.firstPublishedAt, 'YYYY-MM-DD').format(
'LL',
);
}
return { department: departmentPage };
};
const cleanNewsPageData = (newsPage, instanceOfPage, lastPublishedAt) => {
return { ...newsPage, ...instanceOfPage, lastPublishedAt };
};
const getTopicCollectionPageData = async (page, instanceOfPage, client) => {
let topicCollectionPage = { ...page };
const { topicCollectionTopics } = await client.request(
getTopicCollectionTopicQuery,
{
id: topicCollectionPage.id,
},
);
// topicCollectionTopics returns all the topics that are under that topic collection
if (topicCollectionTopics.edges.length) {
topicCollectionPage.topics = topicCollectionTopics.edges
.filter(edge => edge.node.page.topicpage.live)
.map(edge => ({
title: edge.node.page.topicpage.title,
description: edge.node.page.topicpage.description,
slug: edge.node.page.topicpage.slug,
topiccollection: {
slug: topicCollectionPage.slug,
theme: {
slug: topicCollectionPage.theme.slug,
},
},
pages: edge.node.page.topicpage.topPages.edges
// .filter(topPageEdge => topPageEdge.node.live) // todo: can't filter on live now
.map(topPageEdge => ({
pageType: topPageEdge.node.pageType,
title: topPageEdge.node.title,
url: `${instanceOfPage.url}${edge.node.page.topicpage.slug}/${
topPageEdge.node.slug
}/`,
})),
}));
} else {
topicCollectionPage.topics = [];
}
return { tc: topicCollectionPage };
};
const getServicePageData = async (page, instance, client, pagesOfGuides) => {
let servicePage = { ...page };
let relatedTo = [];
if (instance.grandparent) {
relatedTo = await getRelatedTo(
instance.parent,
instance.grandparent,
client,
);
}
// keeping this logic in there for now, stuff is kinda messy
servicePage.contact = cleanContact(servicePage.contact);
servicePage.contextualNavData = {
parent: instance.parent,
relatedTo: relatedTo,
offeredBy: getOfferedByFromDepartments(servicePage.departments),
};
servicePage.events = cleanEvents(servicePage.events);
if (pagesOfGuides && pagesOfGuides[servicePage.id]) {
// We're checking if this id is part of guide page because it may not be published and draw an error.
servicePage.pageIsPartOf = pagesOfGuides[servicePage.id];
}
return { service: servicePage };
};
const getInformationPageData = async (
informationPageData,
instance,
client,
pagesOfGuides,
) => {
let informationPage = { ...informationPageData };
let relatedTo = [];
if (instance.grandparent) {
relatedTo = await getRelatedTo(
instance.parent,
instance.grandparent,
client,
);
}
// keeping this logic in there for now, stuff is kinda messy
informationPage.contact = cleanContact(informationPageData.contact);
informationPage.contextualNavData = {
parent: instance.parent,
relatedTo: relatedTo,
offeredBy: getOfferedByFromDepartments(informationPageData.departments),
};
informationPage.events = cleanEvents(informationPageData.events);
if (pagesOfGuides && pagesOfGuides[informationPageData.id]) {
// We're checking if this id is part of guide page because it may not be published and draw an error.
informationPage.pageIsPartOf = pagesOfGuides[informationPageData.id];
}
return { informationPage: informationPage };
};
const getGuidePageData = async (page, instance, client) => {
let guidePage = { ...page };
let relatedTo = [];
if (instance.grandparent) {
relatedTo = await getRelatedTo(
instance.parent,
instance.grandparent,
client,
);
}
guidePage.contact = cleanContact(guidePage.contact);
guidePage.contextualNavData = {
parent: instance.parent,
relatedTo: relatedTo,
offeredBy: getOfferedByFromDepartments(guidePage.departments),
};
return { guidePage: guidePage };
};
const getFormContainerData = async (fc, instance, client) => {
let formContainer = { ...fc };
let relatedTo = [];
if (instance.grandparent) {
relatedTo = await getRelatedTo(
instance.parent,
instance.grandparent,
client,
);
}
formContainer.contact = cleanContact(formContainer.contact);
formContainer.contextualNavData = {
parent: instance.parent,
relatedTo: relatedTo,
offeredBy: getOfferedByFromDepartments(formContainer.departments),
};
return { formContainer: formContainer };
};
const getOfficialDocumentCollectionData = async (page, instance, client, pageId) => {
let officialDocumentCollection = { ...page };
officialDocumentCollection.pageId = pageId
let relatedTo = [];
if (instance.grandparent) {
relatedTo = await getRelatedTo(
instance.parent,
instance.grandparent,
client,
);
}
officialDocumentCollection.contextualNavData = {
parent: instance.parent,
relatedTo: relatedTo,
offeredBy: getOfferedByFromDepartments(officialDocumentCollection.departments),
};
officialDocumentCollection.lowerBound = await getOfficialDocumentCollectionLowerBound(officialDocumentCollection.id, client);
return { officialDocumentCollection: officialDocumentCollection };
};
const getOfficialDocumentPageData = (page, instance) => {
let officialDocumentPage = { ...page };
if (officialDocumentPage?.document?.filename.slice(-3) === 'pdf') {
officialDocumentPage.pdfSize = filesize(
officialDocumentPage.document.fileSize,
).replace(' ', '');
}
officialDocumentPage.officialDocumentCollection = cleanOfficialDocumentPageCollections(
officialDocumentPage.officialDocumentCollection,
);
officialDocumentPage.contextualNavData = {
// parent: officialDocumentPage.officialDocumentCollection[0],
parent: instance.parent,
relatedTo: [],
offeredBy: getOfferedByFromDepartments(officialDocumentPage.departments),
};
return { officialDocumentPage: officialDocumentPage };
};
const cleanEventPageData = page => {
let eventPage = { ...page };
// Fill in some contextual nav info
eventPage.offeredBy = getOfferedByFromDepartments(eventPage.departments);
// reverse the order of the fees
// eventPage.fees.edges.reverse();
return { eventPage: eventPage };
};
const getDepartmentsPageData = async client => {
const { allDepartmentPages } = await client.request(getDepartmentsPageQuery);
const departments = allDepartmentPages.edges.map(edge => ({
title: edge.node.title,
url: `/${edge.node.slug}/`,
}));
return { departments: departments };
};
const getNewsListForDepartment = async (client, departmentId, locale) => {
const { allPages } = await client.request(getNewsListPageQuery, {
departmentPageId: departmentId,
});
const departmentPage = allPages.edges[0].node.departmentpage;
const parent = {
id: departmentId,
title: departmentPage.title,
url: departmentPage.janisbasepagePtr.janisUrls[0],
};
moment.locale(locale);
const newsList = departmentPage.news.map(newsItem => ({
title: newsItem.title,
url: newsItem.janisbasepagePtr.janisUrls
? newsItem.janisbasepagePtr.janisUrls[0]
: '',
newsDate: moment(newsItem.firstPublishedAt, 'YYYY-MM-DD').format('LL'),
}));
return { newsList: newsList, parent: parent };
};
const getAllEvents = async (client, hideCanceled) => {
const date_now = moment()
.tz('America/Chicago')
.format('YYYY-MM-DD');
const gqlVariables = hideCanceled
? { date_Gte: date_now, canceled: false }
: { date_Gte: date_now };
const { allEventPages } = await client.request(
getEventPageQuery,
gqlVariables,
);
const events = allEventPages.edges.map(edge => ({
title: edge.node.title,
description: edge.node.description,
canceled: edge.node.canceled,
date: edge.node.date,
startTime: edge.node.startTime,
endTime: edge.node.endTime,
eventUrl: getEventPageUrl(edge.node.slug, edge.node.date),
feesRange: formatFeesRange(edge.node.fees),
// until we have support for multiple locations, we're taking the first one
location: edge.node.locations[0],
eventIsFree: edge.node.eventIsFree,
registrationUrl: edge.node.registrationUrl,
}));
return { events: events };
};
const buildPageAtUrl = async (
pageAtUrlInfo,
instanceOfPage,
client,
pagesOfGuides,
) => {
/*
buildPageAtUrl takes a page information object and the language client
returns object with page url, template and data from appropriate query
*/
const {
pageId,
janisUrls,
janisInstances,
eventpage,
locationpage,
departmentpage,
officialdocumentpage,
topiccollectionpage,
janisbasepagewithtopiccollections,
janisbasepagewithtopics,
allDepartments,
allEvents,
newspage,
lastPublishedAt,
} = pageAtUrlInfo;
if (departmentpage) {
let locale = 'en';
if (['en', 'es'].includes(client.options.headers['Accept-Language'])) {
locale = client.options.headers['Accept-Language'];
}
const departmentNewsPage = {
path: 'news',
template: 'src/components/Pages/News/NewsList',
getData: async () =>
await getNewsListForDepartment(client, departmentpage.id, locale),
};
return {
path: instanceOfPage.url,
template: 'src/components/Pages/Department',
children: [departmentNewsPage],
getData: () => cleanDepartmentPageData(departmentpage, locale),
};
}
// If we are a topic collection page, we need to use a query to get information about
// our child topics and their top pages
if (topiccollectionpage) {
return {
path: instanceOfPage.url,
template: 'src/components/Pages/TopicCollection',
getData: async () =>
await getTopicCollectionPageData(topiccollectionpage, instanceOfPage, client),
};
}
if (janisbasepagewithtopiccollections) {
let topicPage = janisbasepagewithtopiccollections.topicpage;
return {
path: instanceOfPage.url,
template: 'src/components/Pages/Topic',
getData: async () => await getTopicPageData(topicPage, instanceOfPage, client),
};
}
if (janisbasepagewithtopics) {
const {
guidepage,
servicepage,
informationpage,
officialdocumentcollection,
formcontainer,
} = janisbasepagewithtopics;
if (guidepage) {
return {
path: instanceOfPage.url,
template: 'src/components/Pages/Guide',
getData: async () => await getGuidePageData(guidepage, instanceOfPage, client),
};
}
if (servicepage) {
return {
path: instanceOfPage.url,
template: 'src/components/Pages/Service',
getData: async () =>
await getServicePageData(
servicepage,
instanceOfPage,
client,
pagesOfGuides.servicePage,
),
};
}
if (informationpage) {
return {
path: instanceOfPage.url,
template: 'src/components/Pages/Information',
getData: async () =>
await getInformationPageData(
informationpage,
instanceOfPage,
client,
pagesOfGuides.informationPage,
),
};
}
if (officialdocumentcollection) {
return {
path: instanceOfPage.url,
template: 'src/components/Pages/OfficialDocuments/OfficialDocumentCollection',
getData: async () =>
await getOfficialDocumentCollectionData(
officialdocumentcollection,
instanceOfPage,
client,
pageId,
),
};
}
if (formcontainer) {
return {
path: instanceOfPage.url,
template: 'src/components/Pages/Form',
getData: async () =>
await getFormContainerData(formcontainer, instanceOfPage, client),
};
}
}
if (locationpage) {
return {
path: janisUrls[0],
template: 'src/components/Pages/Location',
getData: () => cleanLocationPage(locationpage),
};
}
if (eventpage) {
return {
path: janisUrls[0],
template: 'src/components/Pages/Event',
getData: () => cleanEventPageData(eventpage),
};
}
// If we're the departments page
if (allDepartments) {
return {
path: '/departments/',
template: 'src/components/Pages/Departments',
getData: async () => await getDepartmentsPageData(client),
};
}
// If we are the list of all events
if (allEvents) {
return {
path: '/events/',
template: 'src/components/Pages/EventList',
// getAllEvents takes client and boolean: if we should hide the cancelled events
getData: async () => await getAllEvents(client, false),
};
}
// If we are a news page
if (newspage) {
return {
path: instanceOfPage.url,
template: 'src/components/Pages/News',
getData: () =>
cleanNewsPageData(newspage, instanceOfPage, lastPublishedAt),
};
}
if (officialdocumentpage) {
return {
path: instanceOfPage.url,
template: 'src/components/Pages/OfficialDocuments/OfficialDocumentPage',
getData: async () => await getOfficialDocumentPageData(officialdocumentpage, instanceOfPage),
}
}
return {
path: '404',
template: 'src/components/Pages/404',
}
};
const getPagesOfGuidesData = async client => {
const { allGuidePages } = await client.request(getAllGuidePagesSectionsQuery);
const pagesOfGuidesData = {};
await Promise.all(allGuidePages.edges.map(async guidePage => {
if (guidePage.node.sections.length > 0) {
const guideUrl = await client.request(getPageUrlQuery, {
id: guidePage.node.id,
});
let url = '/';
if (
guideUrl.allPages &&
guideUrl.allPages.edges &&
guideUrl.allPages.edges[0].node &&
guideUrl.allPages.edges[0].node.janisInstances
) {
url = guideUrl.allPages.edges[0].node.janisInstances[0].url;
}
guidePage.node.sections.map(section => {
// Example section object
/*
{
heading: 'Learn and prepare',
pages: [
{ servicePage: null, informationPage: [Object] },
{ servicePage: [Object], informationPage: null },
]
}
*/
for (const pageType of ['servicePage', 'informationPage']) {
if (!pagesOfGuidesData[pageType]) {
pagesOfGuidesData[pageType] = {};
}
for (const pageEntry of section.pages) {
const page = pageEntry[pageType];
// Example page object
/*
{
id: 'SW5mb3JtYXRpb25QYWdlTm9kZToyNTc=',
pageType: 'information page',
title: 'Documents for mobile food vendors in Austin'
}
*/
if (page) {
if (!pagesOfGuidesData[pageType][page.id]) {
pagesOfGuidesData[pageType][page.id] = [];
}
pagesOfGuidesData[pageType][page.id].push({
pageName: page.title,
pageType: page.pageType,
ofPageType: guidePage.node.pageType,
guidePageTitle: guidePage.node.title,
guidePageUrl: url,
});
}
}
}
});
}
}));
return pagesOfGuidesData;
};
const makeAllPages = async (langCode, incrementalPageId) => {
/*
makeAllPages returns react-static data object with homepage
and all built pages as children for '/en', '/es' and '/'
*/
const path = `/${langCode || ''}`
console.log(`- Building routes for ${path}...`);
const client = await createGraphQLClientsByLang(langCode);
let pages = [];
let after = '';
let batchSize = Number(process.env.GRAPHQL_BATCH_SIZE) || null;
if (!batchSize) {
if (process.env.DEPLOY_ENV === "production") {
// Our production Joplin dyno is larger and has more resources to process more requests without timing out.
batchSize = 10
} else {
batchSize = 10
}
}
while (true) {
const siteStructure = await client.request(allPagesQuery, { after: after, batchSize: batchSize});
pages = pages.concat(siteStructure.allPages.edges);
after = siteStructure.allPages.pageInfo.endCursor;
if (!siteStructure.allPages.pageInfo.hasNextPage) {
break;
}
}
/**
Build search index here before pages are altered.
**/
// const USE_ELASTICSEARCH = false
// const indexName = `local_${langCode}_${Date.now()}`
// const searchIndex = await searchIndexBuilder(pages, indexName, USE_ELASTICSEARCH)
// incremental build code, may be obsolete with v3
if (incrementalPageId) {
console.log("Looks like we're trying to do an incremental build!");
// First let's find all of the parent/grandparent ids we need
// to rebuild titles on links etc.
let idsToRebuild = [incrementalPageId];
for (const pageAtUrlInfo of parsedStructure) {
if (pageAtUrlInfo.id === incrementalPageId) {
if (pageAtUrlInfo.parent_department) {
idsToRebuild.push(pageAtUrlInfo.parent_department);
}
if (pageAtUrlInfo.parent_topic) {
idsToRebuild.push(pageAtUrlInfo.parent_topic);
}
if (pageAtUrlInfo.grandparent_topic_collection) {
idsToRebuild.push(pageAtUrlInfo.grandparent_topic_collection);
}
}
}
parsedStructure = parsedStructure.filter(pageAtUrlInfo =>
idsToRebuild.includes(pageAtUrlInfo.id),
);
}
const pagesOfGuidesData = await getPagesOfGuidesData(client);
// Build a page with all the departments
pages.push({
node: {
allDepartments: true,
janisInstances: [
{
url: '/departments/',
},
],
},
});
// and also a page with all the events
pages.push({
node: {
allEvents: true,
janisInstances: [
{
url: '/events/',
},
],
},
});
let allPages = await Promise.all(
pages.map(async pageAtUrlInfo => {
if (!!pageAtUrlInfo.node.janisInstances.length) {
return await Promise.all(
pageAtUrlInfo.node.janisInstances.map(async instanceOfPage =>
await buildPageAtUrl(
pageAtUrlInfo.node,
instanceOfPage,
client,
pagesOfGuidesData,
),
),
);
}
// not all pages have instances (events and locations not under departments)
return await Promise.all(
pageAtUrlInfo.node.janisUrls.map(async instanceOfPage =>
await buildPageAtUrl(
pageAtUrlInfo.node,
instanceOfPage,
client,
pagesOfGuidesData,
),
),
);
}),
);
// the nested maps return nested arrays that need to be flattened
allPages = allPages.flat();
allPages.push({
path: '/search/',
template: 'src/components/Pages/Search',
});
const data = {
path: path,
template: 'src/components/Pages/Home',
children: allPages,
getData: async () => {
const { allHomePages } = await client.request(getHomePagesQuery);
let topPages = allHomePages.edges[0].node.topPages
// If no topPages were set, then default to using old method of getting the top 4 service pages
if (!topPages.edges.length) {
const { allServicePages } = await client.request(topServicesQuery);
topPages = allServicePages
}
let services = cleanLinks(topPages, 'service');
// Make sure we don't have any dupes in top services
services = services.filter(
(service, index) =>
index === services.findIndex(s => s.id === service.id),
);
const topServices = services.map(s => ({
type: langCode || 'en',
url: s.url,
title: s.title,
}));
const allActiveEvents = await getAllEvents(client, true);
return {
topServices,
image: {
file: 'banner_image', // Previous image for reference: tomek-baginski-593896-unsplash
title: 'Lady Bird Lake',
},
events: allActiveEvents.events,
};
},
};
return data;
};
export default {
siteRoot: process.env.DEPLOY_ENV === "production" ? 'https://alpha.austin.gov' : '/',
// basePath // Do not alter this line if you want a working PR
basePath: process.env.BASE_PATH_PR ? process.env.BASE_PATH_PR : '/',
stagingSiteRoot: 'https://janis-staging.herokuapp.com/',
getSiteProps: () => ({
title: 'City of Austin',
}),
getSiteData: async () => {
// getSiteData's result is made available to the entire site via the useSiteData hook
const data = {'navigation': {}}
await Promise.all(SUPPORTED_LANG_CODES.map(async langCode => {
const client = await createGraphQLClientsByLang(langCode);
let response = await client.request(allThemesQuery);
data['navigation'][langCode] = cleanNavigation(response, langCode)
}))
return data;
},
getRoutes: async ({ incremental }) => {
let incrementalPageId = null;
if (incremental) {
// TODO: Make sure we have an id of the page that was updated
incrementalPageId = process.env.PAGE_ID;
console.log(
`Incrementally rebuilding page with id: ${incrementalPageId}`,
);
}
const routes = [
{
path: '404',
template: 'src/components/Pages/404',
},
];
await Promise.all(
SUPPORTED_LANG_CODES.map(async (langCode) => {
const pagesData = await makeAllPages(langCode, incrementalPageId)
routes.push(pagesData)
if (langCode === "en") {
// Create pages without a path prefix for default routes using English data.
// const defaultPagesData = Object.assign({}, pagesData, {path: '/'})
const defaultPagesData = cloneDeep(pagesData);
defaultPagesData.path = '/'
routes.push(defaultPagesData)
}
})
);
return routes
},
plugins: ['react-static-plugin-react-router', 'react-static-plugin-sitemap'],
};