@@ -18,7 +18,6 @@ import { PAGE_METADATA } from './constants';
1818
1919// Constants
2020const BASE_URL_PATH = `${ BASE_URL } ${ BASE_PATH } ` ;
21- const MARKDOWN_EXTENSIONS = [ '.mdx' , '.md' , '/index.mdx' , '/index.md' ] as const ;
2221const INDEX_PATTERN = / ( ( \/ ) ? ( i n d e x ) ) ? \. m d x ? $ / i;
2322
2423// Cache for pathname to filename mappings
@@ -28,7 +27,9 @@ const pathnameToFilename = new Map<string, string>();
2827 * Normalizes a path to always use forward slashes
2928 */
3029const normalizePath = ( path : string ) : string =>
31- normalize ( path ) . replace ( / \\ / g, '/' ) ;
30+ normalize ( path )
31+ . replace ( / \\ / g, '/' )
32+ . replace ( / ^ \. \/ / , '' ) ;
3233
3334/**
3435 * Normalizes a filename into a pathname by removing file extensions and index suffixes
@@ -41,29 +42,26 @@ const normalizePathname = (filename: string): string => {
4142 pathname = pathname . slice ( 0 , - 1 ) ;
4243 }
4344
44- return normalizePath ( pathname ) . replace ( / ^ \. \/ / , '' ) ;
45+ return normalizePath ( pathname ) ;
4546} ;
4647
4748/**
48- * Constructs the import path for a markdown file
49- */
50- const buildImportPath = (
51- locale : string ,
52- pathname : string ,
53- extension : string
54- ) : string => `../../../packages/content/src/${ locale } /${ pathname } ${ extension } ` ;
55-
56- /**
57- * Attempts to import a markdown file with a specific extension
49+ * Attempts to import a markdown file for a given locale and pathname
5850 */
59- const tryImportWithExtension = async (
51+ const tryImportMarkdown = async (
6052 locale : string ,
61- normalizedPath : string ,
62- extension : string
53+ pathname : string
6354) : Promise < MarkdownFile | null > => {
55+ const normalizedPath = normalizePath ( pathname ) ;
56+ const filename = pathnameToFilename . get ( normalizedPath . replace ( / ^ \. \/ / , '' ) ) ;
57+
58+ if ( ! filename ) {
59+ return null ;
60+ }
61+
6462 try {
6563 const mod = await import (
66- buildImportPath ( locale , normalizedPath , extension )
64+ `../../../packages/content/src/ ${ locale } / ${ filename } `
6765 ) ;
6866
6967 return {
@@ -72,37 +70,13 @@ const tryImportWithExtension = async (
7270 readingTime : mod . readingTime ,
7371 headings : mod . headings ,
7472 pathname : `/${ normalizedPath } ` ,
75- filename : pathnameToFilename . get ( normalizedPath . replace ( / ^ \. \/ / , '' ) ) ! ,
73+ filename,
7674 } ;
7775 } catch {
7876 return null ;
7977 }
8078} ;
8179
82- /**
83- * Attempts to import a markdown file for a given locale and pathname
84- * Tries multiple file extensions in order of preference
85- */
86- const tryImportMarkdown = async (
87- locale : string ,
88- pathname : string
89- ) : Promise < MarkdownFile | null > => {
90- const normalizedPath = normalizePath ( pathname ) ;
91-
92- for ( const extension of MARKDOWN_EXTENSIONS ) {
93- const result = await tryImportWithExtension (
94- locale ,
95- normalizedPath ,
96- extension
97- ) ;
98- if ( result ) {
99- return result ;
100- }
101- }
102-
103- return null ;
104- } ;
105-
10680/**
10781 * Retrieves a markdown file with locale fallback support
10882 * Tries the requested locale first, then falls back to the default locale
@@ -207,9 +181,7 @@ export const getPageMetadata = cache(async (locale: string, path: string) => {
207181/**
208182 * All available routes in the application
209183 */
210- export const allRoutes = (
211- await getMarkdownFiles ( process . cwd ( ) , `pages/${ defaultLocale . code } ` )
212- )
184+ export const allRoutes = ( await getMarkdownFiles ( ) )
213185 . map ( filename => {
214186 const pathname = normalizePathname ( filename ) ;
215187 pathnameToFilename . set ( pathname , filename ) ;
0 commit comments