@@ -16,10 +16,10 @@ import { HomePage } from '@custom/ui/routes/HomePage';
1616import { Inquiry } from '@custom/ui/routes/Inquiry' ;
1717import { NotFoundPage } from '@custom/ui/routes/NotFoundPage' ;
1818import { Page } from '@custom/ui/routes/Page' ;
19- import React from 'react' ;
19+ import { Providers } from '@custom/ui/routes/Providers' ;
20+ import React , { PropsWithChildren } from 'react' ;
2021import { createPages } from 'waku' ;
2122
22- import { BrokenLinkHandler } from './broken-link-handler.js' ;
2323import { ClientExecutors } from './executors-client.js' ;
2424import { ServerExecutors , serverExecutors } from './executors-server.js' ;
2525import { query } from './query.js' ;
@@ -36,58 +36,44 @@ async function queryAll<TOperation extends AnyOperationId>(
3636 ) ;
3737}
3838
39- export default createPages ( async ( { createPage, createLayout } ) => {
40- createLayout ( {
41- render : 'static' ,
42- path : '/' ,
43- component : ( { children, path } ) => (
44- < BrokenLinkHandler >
45- < LocationProvider
46- currentLocation = { {
47- pathname : path ,
48- searchParams : new URLSearchParams ( ) ,
49- search : '' ,
50- hash : '' ,
51- } }
52- >
53- < ServerExecutors >
54- < ClientExecutors >
55- < Frame alterSrc = { ( src ) => src . replace ( frontendUrl , drupalUrl ) } >
56- { children }
57- </ Frame >
58- </ ClientExecutors >
59- </ ServerExecutors >
60- </ LocationProvider >
61- </ BrokenLinkHandler >
62- ) ,
63- } ) ;
64-
65- Object . values ( Locale ) . forEach ( ( lang ) => {
66- createPage ( {
67- render : 'static' ,
68- path : `/${ lang } ` ,
69- component : ( ) => < HomePage /> ,
70- } ) ;
71-
72- createPage ( {
73- render : 'static' ,
74- path : `/${ lang } /content-hub` ,
75- component : ( ) => < ContentHub pageSize = { 6 } /> ,
76- } ) ;
77-
78- createPage ( {
79- render : 'static' ,
80- path : `/${ lang } /inquiry` ,
81- component : ( ) => < Inquiry /> ,
82- } ) ;
83- } ) ;
39+ function Layout ( { children } : PropsWithChildren ) {
40+ return (
41+ < ServerExecutors >
42+ < ClientExecutors >
43+ < Providers alterSrc = { ( src ) => src . replace ( frontendUrl , drupalUrl ) } >
44+ { children }
45+ </ Providers >
46+ </ ClientExecutors >
47+ </ ServerExecutors >
48+ ) ;
49+ }
8450
85- createPage ( {
86- render : 'static' ,
87- path : '/404' ,
88- component : ( ) => < NotFoundPage /> ,
89- } ) ;
51+ function withPageWrapper ( Component : React . FC ) {
52+ return function PageWrapper ( { path } : { path : string } ) {
53+ return (
54+ < LocationProvider
55+ currentLocation = { {
56+ pathname : path ,
57+ searchParams : new URLSearchParams ( ) ,
58+ search : '' ,
59+ hash : '' ,
60+ } }
61+ >
62+ < ServerExecutors >
63+ < ClientExecutors >
64+ < Providers alterSrc = { ( src ) => src . replace ( frontendUrl , drupalUrl ) } >
65+ < Frame >
66+ < Component />
67+ </ Frame >
68+ </ Providers >
69+ </ ClientExecutors >
70+ </ ServerExecutors >
71+ </ LocationProvider >
72+ ) ;
73+ } ;
74+ }
9075
76+ export default createPages ( async ( { createPage, createLayout } ) => {
9177 // Initialise a map for the homepages, since we want to exclude them from
9278 // creating a page for their internal path.
9379 const homePages = await query ( HomePageQuery , { } ) ;
@@ -119,10 +105,46 @@ export default createPages(async ({ createPage, createLayout }) => {
119105 } ) ;
120106 }
121107
122- createPage ( {
123- render : 'static' ,
124- path : '/[...path]' ,
125- staticPaths : [ ...pagePaths ] . map ( ( path ) => path . substring ( 1 ) . split ( '/' ) ) ,
126- component : Page ,
127- } ) ;
108+ return [
109+ createLayout ( {
110+ render : 'static' ,
111+ path : '/' ,
112+ component : Layout ,
113+ } ) ,
114+
115+ ...Object . values ( Locale )
116+ . map ( ( lang ) => [
117+ createPage ( {
118+ render : 'static' ,
119+ path : `/${ lang } ` ,
120+ component : withPageWrapper ( HomePage ) ,
121+ } ) ,
122+
123+ createPage ( {
124+ render : 'static' ,
125+ path : `/${ lang } /content-hub` ,
126+ component : ( ) => < ContentHub pageSize = { 6 } /> ,
127+ } ) ,
128+
129+ createPage ( {
130+ render : 'static' ,
131+ path : `/${ lang } /inquiry` ,
132+ component : withPageWrapper ( Inquiry ) ,
133+ } ) ,
134+ ] )
135+ . reduce ( ( acc , val ) => [ ...acc , ...val ] ) ,
136+
137+ createPage ( {
138+ render : 'static' ,
139+ path : '/404' ,
140+ component : withPageWrapper ( NotFoundPage ) ,
141+ } ) ,
142+
143+ createPage ( {
144+ render : 'static' ,
145+ path : '/[...path]' ,
146+ staticPaths : [ ...pagePaths ] . map ( ( path ) => path . substring ( 1 ) . split ( '/' ) ) ,
147+ component : withPageWrapper ( Page ) ,
148+ } ) ,
149+ ] ;
128150} ) ;
0 commit comments