Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions packages/gitbook/src/lib/references.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export async function resolveContentRef(
case 'anchor':
case 'page': {
if (contentRef.space && contentRef.space !== space.id) {
return resolveContentRefInSpace(contentRef.space, context, contentRef);
return resolveContentRefInSpace(contentRef.space, context, contentRef, options);
}

const resolvePageResult =
Expand Down Expand Up @@ -165,7 +165,13 @@ export async function resolveContentRef(
if (document) {
const block = getBlockById(document, anchor);
if (block) {
text = getBlockTitle(block);
// If the anchor points to the current page, we just resolve the text from the block.
// This avoids showing the page title twice.
if (isCurrentPage) {
text = `#${getBlockTitle(block)}`;
} else {
text = `${page.title} #${getBlockTitle(block)}`;
}
}
}
}
Expand Down Expand Up @@ -345,15 +351,16 @@ async function getBestTargetSpace(
async function resolveContentRefInSpace(
spaceId: string,
context: GitBookAnyContext,
contentRef: ContentRef
contentRef: ContentRef,
options: ResolveContentRefOptions = {}
) {
const ctx = await createContextForSpace(spaceId, context);

if (!ctx) {
return null;
}

const resolved = await resolveContentRef(contentRef, ctx.spaceContext);
const resolved = await resolveContentRef(contentRef, ctx.spaceContext, options);

if (!resolved) {
return null;
Expand Down