From 4534ea83c3ebca798f400baa557bd61bdfb9604d Mon Sep 17 00:00:00 2001 From: Zeno Kapitein Date: Tue, 4 Nov 2025 11:36:28 +0100 Subject: [PATCH] Implement unique title tags for sections & variants (#3768) --- .changeset/slimy-pens-travel.md | 5 +++ .../src/components/SitePage/SitePage.tsx | 34 ++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 .changeset/slimy-pens-travel.md diff --git a/.changeset/slimy-pens-travel.md b/.changeset/slimy-pens-travel.md new file mode 100644 index 000000000..388467f75 --- /dev/null +++ b/.changeset/slimy-pens-travel.md @@ -0,0 +1,5 @@ +--- +"gitbook": patch +--- + +Implement unique title tags for sections & variants diff --git a/packages/gitbook/src/components/SitePage/SitePage.tsx b/packages/gitbook/src/components/SitePage/SitePage.tsx index 29bb504a4..d11b3c83a 100644 --- a/packages/gitbook/src/components/SitePage/SitePage.tsx +++ b/packages/gitbook/src/components/SitePage/SitePage.tsx @@ -92,6 +92,30 @@ export async function generateSitePageViewport(context: GitBookSiteContext): Pro }; } +/** + * A string concatenation of the site structure (sections and variants) titles. + */ +function getSiteStructureTitle(context: GitBookSiteContext): string | null { + const { sections, siteSpace, siteSpaces } = context; + + const title = []; + if ( + sections && + sections.current.default === false && // Only if the current section is not the default one + sections.list.filter((section) => section.object === 'site-section').length > 1 // Only if there are multiple sections + ) { + title.push(sections.current.title); + } + if ( + siteSpaces.length > 1 && // Only if there are multiple variants + siteSpace.default === false && // Only if the variant is not the default one + siteSpaces.filter((space) => space.space.language === siteSpace.space.language).length > 1 // Only if there are multiple variants *for the current language*. This filters out spaces that are "just" translations of each other, not versions. + ) { + title.push(siteSpace.title); + } + return title.join(' '); +} + export async function generateSitePageMetadata(props: SitePageProps): Promise { const { context, pageTarget } = await getPageDataWithFallback({ context: props.context, @@ -107,9 +131,17 @@ export async function generateSitePageMetadata(props: SitePageProps): Promise