@@ -6,8 +6,6 @@ export function getMarkdownContent() {
66 const { path : pagePath } = serverContext ( ) ;
77
88 const pathStr = pagePath . join ( '/' ) ;
9-
10- console . log ( `Looking for markdown content for path: ${ pathStr } ` ) ;
119
1210 const possibleExtensions = [ '.mdx' , '.md' ] ;
1311 const basePaths = [
@@ -17,7 +15,7 @@ export function getMarkdownContent() {
1715 ] ;
1816
1917 // Extract SDK information from frontmatter and path
20- const extractSdkInfo = ( content : string , pathStr : string ) : string => {
18+ const extractSdkInfo = ( content : string , filePath : string ) : string => {
2119 // First try to get SDK from frontmatter
2220 const frontmatterMatch = content . match ( / ^ - - - \n ( [ \s \S ] * ?) \n - - - / ) ;
2321 if ( frontmatterMatch ) {
@@ -30,7 +28,7 @@ export function getMarkdownContent() {
3028 }
3129
3230 // If no SDK in frontmatter, try to infer from path
33- const pathSegments = pathStr . split ( '/' ) ;
31+ const pathSegments = filePath . split ( '/' ) ;
3432 if ( pathSegments . length >= 3 && pathSegments [ 0 ] === 'platforms' ) {
3533 // Format: platforms/javascript/guides/node
3634 const platform = pathSegments [ 1 ] ;
@@ -54,7 +52,7 @@ export function getMarkdownContent() {
5452 // Extract all PlatformSection blocks
5553 const platformSectionRegex = / < P l a t f o r m S e c t i o n \s + ( [ ^ > ] * ) > ( [ \s \S ] * ?) < \/ P l a t f o r m S e c t i o n > / g;
5654
57- return content . replace ( platformSectionRegex , ( attributes , sectionContent ) => {
55+ return content . replace ( platformSectionRegex , ( match , attributes , sectionContent ) => {
5856 // Check if this section should be included or excluded based on SDK
5957 const supportedMatch = attributes . match ( / s u p p o r t e d = \{ ( \[ [ ^ \] ] * \] ) \} / ) ;
6058 const notSupportedMatch = attributes . match ( / n o t S u p p o r t e d = \{ ( \[ [ ^ \] ] * \] ) \} / ) ;
@@ -159,7 +157,7 @@ export function getMarkdownContent() {
159157 // Match <PlatformContent includePath="path" /> patterns
160158 const platformContentRegex = / < P l a t f o r m C o n t e n t \s + i n c l u d e P a t h = " ( [ ^ " ] + ) " \s * \/ > / g;
161159
162- return content . replace ( platformContentRegex , ( includePath ) => {
160+ return content . replace ( platformContentRegex , ( match , includePath ) => {
163161 try {
164162 // Platform content is organized by SDK in platform-includes directory
165163 const platformIncludesDir = path . join ( process . cwd ( ) , 'platform-includes' , includePath ) ;
@@ -236,31 +234,31 @@ export function getMarkdownContent() {
236234 const processPlatformTags = ( content : string ) : string => {
237235 // Replace PlatformLink tags
238236 let processedContent = content . replace ( / < P l a t f o r m L i n k \s + t o = " ( [ ^ " ] + ) " > ( [ \s \S ] * ?) < \/ P l a t f o r m L i n k > / g,
239- ( to , linkText ) => `[${ linkText } ](${ to } )` ) ;
237+ ( match , to , linkText ) => `[${ linkText } ](${ to } )` ) ;
240238
241239 // Replace PlatformIdentifier tags
242240 processedContent = processedContent . replace ( / < P l a t f o r m I d e n t i f i e r \s + n a m e = " ( [ ^ " ] + ) " [ ^ > ] * \/ > / g,
243- ( name ) => `\`${ name } \`` ) ;
241+ ( match , name ) => `\`${ name } \`` ) ;
244242
245243 // Replace Alert tags
246244 processedContent = processedContent . replace ( / < A l e r t [ ^ > ] * > ( [ \s \S ] * ?) < \/ A l e r t > / g,
247- ( alertContent ) => `> **Note**\n> ${ alertContent . trim ( ) . replace ( / \n / g, '\n> ' ) } ` ) ;
245+ ( match , alertContent ) => `> **Note**\n> ${ alertContent . trim ( ) . replace ( / \n / g, '\n> ' ) } ` ) ;
248246
249247 // Replace code blocks with tabTitle
250248 processedContent = processedContent . replace ( / ` ` ` ( [ a - z A - Z ] + ) \s + \{ t a b T i t l e : \s * ( [ ^ } ] + ) \} ( [ \s \S ] * ?) ` ` ` / g,
251- ( language , title , code ) => `**${ title . trim ( ) } **\n\n\`\`\`${ language } \n${ code . trim ( ) } \n\`\`\`` ) ;
249+ ( match , language , title , code ) => `**${ title . trim ( ) } **\n\n\`\`\`${ language } \n${ code . trim ( ) } \n\`\`\`` ) ;
252250
253251 return processedContent ;
254252 } ;
255253
256- const processIncludes = ( content : string , pathStr : string ) : string => {
254+ const processIncludes = ( content : string , filePath : string ) : string => {
257255 // Extract SDK information
258- const sdk = extractSdkInfo ( content , pathStr ) ;
256+ const sdk = extractSdkInfo ( content , filePath ) ;
259257
260258 // First process regular includes
261259 const includeRegex = / < I n c l u d e \s + n a m e = " ( [ ^ " ] + ) " \s * \/ > / g;
262260
263- let processedContent = content . replace ( includeRegex , ( includeName ) => {
261+ let processedContent = content . replace ( includeRegex , ( match , includeName ) => {
264262 const includePath = path . join ( process . cwd ( ) , 'includes' , includeName ) ;
265263
266264 if ( fs . existsSync ( includePath ) ) {
@@ -301,10 +299,10 @@ export function getMarkdownContent() {
301299 return processedContent ;
302300 } ;
303301
304- const readAndProcessMarkdown = ( filePath : string , pathStr : string ) : string => {
302+ const readAndProcessMarkdown = ( filePath : string , currentPath : string ) : string => {
305303 try {
306304 const content = fs . readFileSync ( filePath , 'utf8' ) ;
307- return processIncludes ( content , pathStr ) ;
305+ return processIncludes ( content , currentPath ) ;
308306 } catch ( error ) {
309307 return `<!-- Error reading file: ${ filePath } -->` ;
310308 }
@@ -472,7 +470,7 @@ export function getMarkdownContent() {
472470
473471 const markdownFiles = findMarkdownFiles ( baseDir ) ;
474472
475- const pathSegments = pathStr . split ( '/' ) ;
473+ const pathSegmentsToMatch = pathStr . split ( '/' ) ;
476474
477475 const exactPathMatch = markdownFiles . find ( file => {
478476 const relativePath = path . relative ( basePath , file ) ;
@@ -491,7 +489,7 @@ export function getMarkdownContent() {
491489 const relativePath = path . relative ( basePath , file ) . toLowerCase ( ) ;
492490 let remainingPath = relativePath . toLowerCase ( ) ;
493491
494- for ( const segment of pathSegments ) {
492+ for ( const segment of pathSegmentsToMatch ) {
495493 const segmentLower = segment . toLowerCase ( ) ;
496494 const segmentIndex = remainingPath . indexOf ( segmentLower ) ;
497495
@@ -512,7 +510,7 @@ export function getMarkdownContent() {
512510 const containsAllSegmentsFile = markdownFiles . find ( file => {
513511 const relativePath = path . relative ( basePath , file ) . toLowerCase ( ) ;
514512
515- return pathSegments . every ( segment =>
513+ return pathSegmentsToMatch . every ( segment =>
516514 relativePath . includes ( segment . toLowerCase ( ) )
517515 ) ;
518516 } ) ;
@@ -521,7 +519,7 @@ export function getMarkdownContent() {
521519 return readAndProcessMarkdown ( containsAllSegmentsFile , pathStr ) ;
522520 }
523521
524- const lastSegment = pathSegments [ pathSegments . length - 1 ] ;
522+ const lastSegment = pathSegmentsToMatch [ pathSegmentsToMatch . length - 1 ] ;
525523 const matchingIndexFile = markdownFiles . find ( file => {
526524 const relativePath = path . relative ( basePath , file ) . toLowerCase ( ) ;
527525 return relativePath . includes ( `/${ lastSegment . toLowerCase ( ) } /index.` ) ;
0 commit comments