@@ -230,6 +230,25 @@ function buildUrl(relativePath: string, baseUrl?: string): string {
230
230
return `${ BASE_URL } ${ url } ` ;
231
231
}
232
232
233
+ /**
234
+ * Build path from relative path (without base URL)
235
+ */
236
+ function buildPath ( relativePath : string , baseUrl ?: string ) : string {
237
+ if ( baseUrl ) {
238
+ // For API docs, return relative path with baseUrl
239
+ return `${ baseUrl } /${ relativePath } ` ;
240
+ }
241
+
242
+ let path = relativePath . replace ( / \. ( m d | m d x ) $ / , "" ) ;
243
+ if ( path . endsWith ( "/index" ) ) {
244
+ path = path . replace ( / \/ i n d e x $ / , "/" ) ;
245
+ }
246
+ if ( ! path . startsWith ( "/" ) ) {
247
+ path = "/" + path ;
248
+ }
249
+ return path ;
250
+ }
251
+
233
252
/**
234
253
* Process a single API symbol from reference documentation
235
254
*/
@@ -239,11 +258,11 @@ function processApiSymbol(
239
258
apiType : string ,
240
259
baseUrl : string ,
241
260
packageName : string ,
242
- ) : OramaDocument | null {
261
+ ) : OramaDocument [ ] {
243
262
try {
244
263
// Type guard for symbolData
245
264
if ( ! symbolData || typeof symbolData !== "object" ) {
246
- return null ;
265
+ return [ ] ;
247
266
}
248
267
249
268
const data = symbolData as Record < string , unknown > ;
@@ -255,6 +274,9 @@ function processApiSymbol(
255
274
const htmlHeadCtx = data . html_head_ctx as
256
275
| Record < string , unknown >
257
276
| undefined ;
277
+ const tocCtx = data . toc_ctx as
278
+ | Record < string , unknown >
279
+ | undefined ;
258
280
259
281
const symbolName = symbolGroupCtx ?. name as string ||
260
282
symbolPath . split ( "." ) . pop ( ) || "Unknown" ;
@@ -315,7 +337,7 @@ function processApiSymbol(
315
337
316
338
// Skip if no meaningful content
317
339
if ( content . length < 20 ) {
318
- return null ;
340
+ return [ ] ;
319
341
}
320
342
321
343
// Determine symbol type
@@ -348,15 +370,20 @@ function processApiSymbol(
348
370
}
349
371
}
350
372
351
- // Build clean URL
352
- const cleanPath = symbolPath . replace ( / ^ \. \/ ~ \/ / , "" ) . replace ( / \. j s o n $ / , "" ) ;
373
+ // Build clean URL - preserve the ~/ prefix for API paths
374
+ const cleanPath = symbolPath . replace ( / ^ \. \/ / , "" ) . replace ( / \. j s o n $ / , "" ) ;
353
375
const url = buildUrl ( cleanPath , baseUrl ) ;
376
+ const path = buildPath ( cleanPath , baseUrl ) ;
354
377
355
- return {
378
+ const documents : OramaDocument [ ] = [ ] ;
379
+
380
+ // Create main document for the symbol
381
+ documents . push ( {
356
382
id : generateId ( cleanPath , apiType ) ,
357
383
title : title . replace ( " - Deno documentation" , "" ) ,
358
384
content : content . trim ( ) ,
359
385
url,
386
+ path,
360
387
category : `api-${ apiType } ` ,
361
388
section : packageName . toLowerCase ( ) ,
362
389
subsection : symbolType ,
@@ -370,10 +397,48 @@ function processApiSymbol(
370
397
symbolPath : symbolName ,
371
398
packageName,
372
399
} ,
373
- } ;
400
+ } ) ;
401
+
402
+ // Process TOC entries to create anchor documents
403
+ const documentNavigation = tocCtx ?. document_navigation as unknown [ ] | undefined ;
404
+ if ( documentNavigation && Array . isArray ( documentNavigation ) ) {
405
+ for ( const navItem of documentNavigation ) {
406
+ if ( navItem && typeof navItem === "object" ) {
407
+ const navObj = navItem as Record < string , unknown > ;
408
+ const anchor = navObj . anchor as string | undefined ;
409
+ const navContent = navObj . content as string | undefined ;
410
+
411
+ if ( anchor && navContent ) {
412
+ // Create a document for this anchor
413
+ documents . push ( {
414
+ id : generateId ( `${ cleanPath } -${ anchor } ` , apiType ) ,
415
+ title : `${ symbolName } .${ navContent } ` ,
416
+ content : `${ navContent } ${ content . trim ( ) } ` ,
417
+ url : `${ url } #${ anchor } ` ,
418
+ path : `${ path } #${ anchor } ` ,
419
+ category : `api-${ apiType } ` ,
420
+ section : packageName . toLowerCase ( ) ,
421
+ subsection : symbolType ,
422
+ description : `${ navContent } - ${ symbolType } in the ${ packageName } API` ,
423
+ tags : [ ...tags , "anchor" ] ,
424
+ headings : [ navContent ] ,
425
+ lastModified : Date . now ( ) ,
426
+ docType : "api-reference" ,
427
+ apiInfo : {
428
+ symbolType,
429
+ symbolPath : symbolName ,
430
+ packageName,
431
+ } ,
432
+ } ) ;
433
+ }
434
+ }
435
+ }
436
+ }
437
+
438
+ return documents ;
374
439
} catch ( error ) {
375
440
console . error ( `Error processing API symbol ${ symbolPath } :` , error ) ;
376
- return null ;
441
+ return [ ] ;
377
442
}
378
443
}
379
444
@@ -409,17 +474,17 @@ async function processReferenceDocumentation(): Promise<OramaDocument[]> {
409
474
continue ;
410
475
}
411
476
412
- const doc = processApiSymbol (
477
+ const docs = processApiSymbol (
413
478
symbolPath ,
414
479
symbolData ,
415
480
refFile . apiType ,
416
481
refFile . baseUrl ,
417
482
refFile . apiType . charAt ( 0 ) . toUpperCase ( ) + refFile . apiType . slice ( 1 ) ,
418
483
) ;
419
484
420
- if ( doc ) {
421
- documents . push ( doc ) ;
422
- processed ++ ;
485
+ if ( docs && docs . length > 0 ) {
486
+ documents . push ( ... docs ) ;
487
+ processed += docs . length ;
423
488
} else {
424
489
skipped ++ ;
425
490
}
@@ -535,14 +600,16 @@ async function collectMarkdownFiles(): Promise<OramaDocument[]> {
535
600
relativePath ,
536
601
) ;
537
602
538
- // Build URL
603
+ // Build URL and path
539
604
const url = buildUrl ( relativePath ) ;
605
+ const path = buildPath ( relativePath ) ;
540
606
541
607
files . push ( {
542
608
id : generateId ( relativePath ) ,
543
609
title,
544
610
content : prefixedContent ,
545
611
url,
612
+ path,
546
613
category,
547
614
section,
548
615
subsection : subsection || undefined ,
0 commit comments