@@ -17,11 +17,7 @@ import {
1717 ENABLE_STATIC_EXPORT_LOCALE ,
1818 ENABLE_STATIC_EXPORT ,
1919} from '#site/next.constants.mjs' ;
20- import {
21- PAGE_VIEWPORT ,
22- DYNAMIC_ROUTES ,
23- DYNAMIC_MARKDOWN_ROUTES ,
24- } from '#site/next.dynamic.constants.mjs' ;
20+ import { PAGE_VIEWPORT } from '#site/next.dynamic.constants.mjs' ;
2521import { dynamicRouter } from '#site/next.dynamic.mjs' ;
2622import { allLocaleCodes , availableLocaleCodes } from '#site/next.locales.mjs' ;
2723import { defaultLocale } from '#site/next.locales.mjs' ;
@@ -96,33 +92,6 @@ const getPage: FC<DynamicParams> = async props => {
9692 // Gets the current full pathname for a given path
9793 const pathname = dynamicRouter . getPathname ( path ) ;
9894
99- const staticGeneratedLayout = DYNAMIC_ROUTES . get ( pathname ) ;
100-
101- // If the current pathname corresponds to a statically generated route but does
102- // not have a dynamic Markdown file, it means there is no Markdown file on the
103- // filesystem for it. However, it is still a valid route with an assigned layout
104- // that should be rendered.
105- if (
106- staticGeneratedLayout !== undefined &&
107- ! DYNAMIC_MARKDOWN_ROUTES . has ( staticGeneratedLayout )
108- ) {
109- // Metadata and shared Context to be available through the lifecycle of the page
110- const sharedContext = { pathname : `/${ pathname } ` } ;
111-
112- // Defines a shared Server Context for the Client-Side
113- // That is shared for all pages under the dynamic router
114- setClientContext ( sharedContext ) ;
115-
116- // The Matter Provider allows Client-Side injection of the data
117- // to a shared React Client Provider even though the page is rendered
118- // within a server-side context
119- return (
120- < MatterProvider { ...sharedContext } >
121- < WithLayout layout = { staticGeneratedLayout } />
122- </ MatterProvider >
123- ) ;
124- }
125-
12695 // We retrieve the source of the Markdown file by doing an educated guess
12796 // of what possible files could be the source of the page, since the extension
12897 // context is lost from `getStaticProps` as a limitation of Next.js itself
@@ -131,36 +100,36 @@ const getPage: FC<DynamicParams> = async props => {
131100 pathname
132101 ) ;
133102
134- if ( source . length && filename . length ) {
135- // This parses the source Markdown content and returns a React Component and
136- // relevant context from the Markdown File
137- const { content, frontmatter, headings, readingTime } =
138- await dynamicRouter . getMDXContent ( source , filename ) ;
139-
140- // Metadata and shared Context to be available through the lifecycle of the page
141- const sharedContext = {
142- frontmatter : frontmatter ,
143- headings : headings ,
144- pathname : `/${ pathname } ` ,
145- readingTime : readingTime ,
146- filename : filename ,
147- } ;
148-
149- // Defines a shared Server Context for the Client-Side
150- // That is shared for all pages under the dynamic router
151- setClientContext ( sharedContext ) ;
152-
153- // The Matter Provider allows Client-Side injection of the data
154- // to a shared React Client Provider even though the page is rendered
155- // within a server-side context
156- return (
157- < MatterProvider { ...sharedContext } >
158- < WithLayout layout = { frontmatter . layout } > { content } </ WithLayout >
159- </ MatterProvider >
160- ) ;
103+ if ( source === '' && filename === '' ) {
104+ return notFound ( ) ;
161105 }
162106
163- return notFound ( ) ;
107+ // This parses the source Markdown content and returns a React Component and
108+ // relevant context from the Markdown File
109+ const { content, frontmatter, headings, readingTime } =
110+ await dynamicRouter . getMDXContent ( source , filename ) ;
111+
112+ // Metadata and shared Context to be available through the lifecycle of the page
113+ const sharedContext = {
114+ frontmatter : frontmatter ,
115+ headings : headings ,
116+ pathname : `/${ pathname } ` ,
117+ readingTime : readingTime ,
118+ filename : filename ,
119+ } ;
120+
121+ // Defines a shared Server Context for the Client-Side
122+ // That is shared for all pages under the dynamic router
123+ setClientContext ( sharedContext ) ;
124+
125+ // The Matter Provider allows Client-Side injection of the data
126+ // to a shared React Client Provider even though the page is rendered
127+ // within a server-side context
128+ return (
129+ < MatterProvider { ...sharedContext } >
130+ < WithLayout layout = { frontmatter . layout } > { content } </ WithLayout >
131+ </ MatterProvider >
132+ ) ;
164133} ;
165134
166135// Enforces that this route is used as static rendering
0 commit comments