@@ -27,9 +27,7 @@ const pathnameToFilename = new Map<string, string>();
2727 * Normalizes a path to always use forward slashes
2828 */
2929const normalizePath = ( path : string ) : string =>
30- normalize ( path )
31- . replace ( / \\ / g, '/' )
32- . replace ( / ^ \. \/ / , '' ) ;
30+ normalize ( path ) . replace ( / \\ / g, '/' ) . replace ( / ^ \. \/ / , '' ) ;
3331
3432/**
3533 * Normalizes a filename into a pathname by removing file extensions and index suffixes
@@ -42,7 +40,7 @@ const normalizePathname = (filename: string): string => {
4240 pathname = pathname . slice ( 0 , - 1 ) ;
4341 }
4442
45- return normalizePath ( pathname ) ;
43+ return pathname ;
4644} ;
4745
4846/**
@@ -53,7 +51,7 @@ const tryImportMarkdown = async (
5351 pathname : string
5452) : Promise < MarkdownFile | null > => {
5553 const normalizedPath = normalizePath ( pathname ) ;
56- const filename = pathnameToFilename . get ( normalizedPath . replace ( / ^ \. \/ / , '' ) ) ;
54+ const filename = pathnameToFilename . get ( normalizedPath ) ;
5755
5856 if ( ! filename ) {
5957 return null ;
@@ -84,6 +82,7 @@ const tryImportMarkdown = async (
8482export const getMarkdownFile = cache (
8583 async ( locale : string , pathname : string ) : Promise < MarkdownFile | null > => {
8684 const localized = await tryImportMarkdown ( locale , pathname ) ;
85+
8786 if ( localized ) {
8887 return localized ;
8988 }
@@ -182,9 +181,12 @@ export const getPageMetadata = cache(async (locale: string, path: string) => {
182181 * All available routes in the application
183182 */
184183export const allRoutes = ( await getMarkdownFiles ( ) )
185- . map ( filename => {
184+ . map ( f => {
185+ const filename = normalizePath ( f ) ;
186186 const pathname = normalizePathname ( filename ) ;
187+
187188 pathnameToFilename . set ( pathname , filename ) ;
189+
188190 return pathname ;
189191 } )
190192 . filter ( Boolean ) ;
0 commit comments