@@ -116,7 +116,7 @@ export async function resolveContentRef(
116116 case 'anchor' :
117117 case 'page' : {
118118 if ( contentRef . space && contentRef . space !== space . id ) {
119- return resolveContentRefInSpace ( contentRef . space , context , contentRef ) ;
119+ return resolveContentRefInSpace ( contentRef . space , context , contentRef , options ) ;
120120 }
121121
122122 const resolvePageResult =
@@ -165,7 +165,13 @@ export async function resolveContentRef(
165165 if ( document ) {
166166 const block = getBlockById ( document , anchor ) ;
167167 if ( block ) {
168- text = getBlockTitle ( block ) ;
168+ // If the anchor points to the current page, we just resolve the text from the block.
169+ // This avoids showing the page title twice.
170+ if ( isCurrentPage ) {
171+ text = `#${ getBlockTitle ( block ) } ` ;
172+ } else {
173+ text = `${ page . title } #${ getBlockTitle ( block ) } ` ;
174+ }
169175 }
170176 }
171177 }
@@ -345,15 +351,16 @@ async function getBestTargetSpace(
345351async function resolveContentRefInSpace (
346352 spaceId : string ,
347353 context : GitBookAnyContext ,
348- contentRef : ContentRef
354+ contentRef : ContentRef ,
355+ options : ResolveContentRefOptions = { }
349356) {
350357 const ctx = await createContextForSpace ( spaceId , context ) ;
351358
352359 if ( ! ctx ) {
353360 return null ;
354361 }
355362
356- const resolved = await resolveContentRef ( contentRef , ctx . spaceContext ) ;
363+ const resolved = await resolveContentRef ( contentRef , ctx . spaceContext , options ) ;
357364
358365 if ( ! resolved ) {
359366 return null ;
0 commit comments