Skip to content

Commit ebbb476

Browse files
authored
Improve ancestor label in references (#3761)
1 parent 89655cb commit ebbb476

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

.changeset/puny-suits-boil.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'gitbook': patch
3+
---
4+
5+
Improve ancestor label in references

packages/gitbook/src/lib/references.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,11 +366,29 @@ async function resolveContentRefInSpace(
366366
return null;
367367
}
368368

369+
// Prefer the variant title when available, then the section title, then fallback to the space title.
370+
const ancestorLabel = (() => {
371+
if ('site' in context) {
372+
const foundSiteSpace = findSiteSpaceBy(
373+
context.structure,
374+
(siteSpace) => siteSpace.space.id === spaceId
375+
);
376+
377+
return (
378+
foundSiteSpace?.siteSpace.title ??
379+
foundSiteSpace?.siteSection?.title ??
380+
ctx.spaceContext.space.title
381+
);
382+
}
383+
384+
return ctx.spaceContext.space.title;
385+
})();
386+
369387
return {
370388
...resolved,
371389
ancestors: [
372390
{
373-
label: ctx.spaceContext.space.title,
391+
label: ancestorLabel,
374392
href: ctx.baseURL.toString(),
375393
},
376394
...(resolved.ancestors ?? []),

0 commit comments

Comments
 (0)