diff --git a/.changeset/slimy-pens-travel.md b/.changeset/slimy-pens-travel.md new file mode 100644 index 0000000000..388467f75b --- /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 b519543b83..4eb72ce3bf 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, @@ -104,9 +128,17 @@ export async function generateSitePageMetadata(props: SitePageProps): Promise