@@ -14,6 +14,7 @@ import type {
1414} from '../types' ;
1515import { migrateToVersion0230 } from './structure/0.23' ;
1616import { getKindSlug , getPackageSlug , joinUrl } from './url' ;
17+ import { resolveAnchorLink } from '../utils/links' ;
1718
1819function shouldEmit ( projectRoot : string , tsconfigPath : string ) {
1920 // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
@@ -176,42 +177,43 @@ export function loadPackageJsonAndDocs(
176177}
177178
178179export function addMetadataToReflections (
179- project : JSONOutput . DeclarationReflection ,
180- packageSlug : string ,
181- urlPrefix : string ,
180+ project : JSONOutput . DeclarationReflection ,
181+ packageSlug : string ,
182+ urlPrefix : string ,
182183) : TSDDeclarationReflection {
183- const permalink = `/${ joinUrl ( urlPrefix , packageSlug ) } ` ;
184-
185- if ( project . children ) {
186- // eslint-disable-next-line no-param-reassign
187- project . children = project . children . map ( ( child ) => {
188- migrateToVersion0230 ( child ) ;
189-
190- const kindSlugPart = getKindSlug ( child ) ;
191- const childSlug = kindSlugPart ? `/${ kindSlugPart } /${ child . name } ` : `#${ child . name } ` ;
192- const childPermalink = permalink + childSlug ;
193-
194- // We need to go another level deeper and only use fragments
195- if ( child . kind === ReflectionKind . Namespace && child . children ) {
196- // eslint-disable-next-line no-param-reassign
197- child . children = child . children . map ( ( grandChild ) => ( {
198- ...grandChild ,
199- permalink : normalizeUrl ( [ `${ childPermalink } #${ grandChild . name } ` ] ) ,
200- } ) ) ;
201- }
202-
203- return {
204- ...child ,
205- permalink : normalizeUrl ( [ childPermalink ] ) ,
206- } ;
207- } ) ;
208- }
209-
210- // @ts -expect-error Not sure why this fails
211- return {
212- ...project ,
213- permalink : normalizeUrl ( [ permalink ] ) ,
214- } ;
184+ const permalink = `/${ joinUrl ( urlPrefix , packageSlug ) } ` ;
185+
186+ if ( project . children ) {
187+ // eslint-disable-next-line no-param-reassign
188+ project . children = project . children . map ( ( child ) => {
189+ migrateToVersion0230 ( child ) ;
190+
191+ const kindSlugPart = getKindSlug ( child ) ;
192+ const childPermalink = kindSlugPart
193+ ? `${ permalink } /${ kindSlugPart } /${ child . name } `
194+ : resolveAnchorLink ( permalink , child . name ) ;
195+
196+ // We need to go another level deeper and only use fragments
197+ if ( child . kind === ReflectionKind . Namespace && child . children ) {
198+ // eslint-disable-next-line no-param-reassign
199+ child . children = child . children . map ( ( grandChild ) => ( {
200+ ...grandChild ,
201+ permalink : normalizeUrl ( [ resolveAnchorLink ( childPermalink , grandChild . name ) ] ) ,
202+ } ) ) ;
203+ }
204+
205+ return {
206+ ...child ,
207+ permalink : normalizeUrl ( [ childPermalink ] ) ,
208+ } ;
209+ } ) ;
210+ }
211+
212+ // @ts -expect-error Not sure why this fails
213+ return {
214+ ...project ,
215+ permalink : normalizeUrl ( [ permalink ] ) ,
216+ } ;
215217}
216218
217219function mergeReflections ( base : TSDDeclarationReflection , next : TSDDeclarationReflection ) {
0 commit comments