@@ -15,10 +15,23 @@ import {
1515export const dynamic = "force-static"
1616
1717const INDEX_PAGE_PERMALINK = "_index"
18+
19+ interface ParamsContent {
20+ permalink : string [ ]
21+ }
1822interface DynamicPageProps {
19- params : Promise < {
20- permalink : string [ ]
21- } >
23+ params : Promise < ParamsContent >
24+ }
25+
26+ // Note: permalink should not be able to be undefined
27+ // However, nextjs had some magic props passing going on that causes
28+ // { permalink: [""] } to be converted to {}
29+ // Thus the patch is necessary to convert it back if its undefined
30+ const getPatchedPermalink = async (
31+ props : DynamicPageProps ,
32+ ) : Promise < ParamsContent [ "permalink" ] > => {
33+ const params = await props . params
34+ return params . permalink ?? [ "" ]
2235}
2336
2437const timeNow = new Date ( )
@@ -29,9 +42,8 @@ const lastUpdated =
2942 " " +
3043 timeNow . getFullYear ( )
3144
32- const getSchema = async ( paramsPromise : DynamicPageProps ) => {
33- const { permalink } = await paramsPromise . params
34- const joinedPermalink = ! ! permalink ? permalink . join ( "/" ) : ""
45+ const getSchema = async ( { permalink } : Pick < ParamsContent , "permalink" > ) => {
46+ const joinedPermalink : string = permalink . join ( "/" )
3547
3648 const schema = ( await import ( `@/schema/${ joinedPermalink } .json` )
3749 . then ( ( module ) => module . default )
@@ -56,7 +68,7 @@ const getSchema = async (paramsPromise: DynamicPageProps) => {
5668 // @ts -expect-error to fix when types are proper
5769 getSitemapXml ( sitemap ) . find (
5870 ( { url } ) => joinedPermalink === url . replace ( / ^ \/ / , "" ) ,
59- ) ? .lastModified || new Date ( ) . toISOString ( )
71+ ) . lastModified || new Date ( ) . toISOString ( )
6072
6173 schema . page . permalink = "/" + joinedPermalink
6274 schema . page . lastModified = lastModified
@@ -76,7 +88,9 @@ export const generateMetadata = async (
7688 props : DynamicPageProps ,
7789 _parent : ResolvingMetadata ,
7890) : Promise < Metadata > => {
79- const schema = await getSchema ( props )
91+ const schema = await getSchema ( {
92+ permalink : await getPatchedPermalink ( props ) ,
93+ } )
8094 schema . site = {
8195 ...config . site ,
8296 environment : process . env . NEXT_PUBLIC_ISOMER_NEXT_ENVIRONMENT ,
@@ -94,7 +108,9 @@ export const generateMetadata = async (
94108}
95109
96110const Page = async ( props : DynamicPageProps ) => {
97- const renderSchema = await getSchema ( props )
111+ const renderSchema = await getSchema ( {
112+ permalink : await getPatchedPermalink ( props ) ,
113+ } )
98114
99115 return (
100116 < RenderEngine
0 commit comments