This is an automated email from the ASF dual-hosted git repository.
hubcio pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iggy-website.git
The following commit(s) were added to refs/heads/main by this push:
new 0649604a fix(site): give docs pages a unique document title (#83)
0649604a is described below
commit 0649604a498b9f3b3956fc7b000db917af3237f7
Author: Justin Mclean <[email protected]>
AuthorDate: Mon Sep 7 16:55:31 2026 +1000
fix(site): give docs pages a unique document title (#83)
---
src/app/docs/[[...slug]]/page.tsx | 24 +++++++++++++++++++-----
1 file changed, 19 insertions(+), 5 deletions(-)
diff --git a/src/app/docs/[[...slug]]/page.tsx
b/src/app/docs/[[...slug]]/page.tsx
index bd43140b..83a2e55a 100644
--- a/src/app/docs/[[...slug]]/page.tsx
+++ b/src/app/docs/[[...slug]]/page.tsx
@@ -76,8 +76,14 @@ export async function generateMetadata(props: {
const page = source.getPage(params.slug);
if (!page) notFound();
+ // Several chapters have pages with identical titles ("Introduction",
+ // "Examples"), which gives them identical document titles and pools them
+ // together in analytics and in search results. Prefix the chapter, as the
+ // prev/next footer already does. The on-page heading is left alone.
+ const chapter = chapterName(source.getPageTree(), page.url);
+
return {
- title: page.data.title,
+ title: chapter ? `${chapter}: ${page.data.title}` : page.data.title,
description: page.data.description,
alternates: {
// Set both: defining alternates here replaces the root's, canonical
included.
@@ -93,18 +99,26 @@ export async function generateMetadata(props: {
// Prefix it with the chapter, i.e. the target's nearest parent folder.
function withChapter(tree: PageTree.Root, item: PageTree.Item | undefined) {
if (!item) return undefined;
- const parent = PageTree.findParent(tree, item.url);
- // The tree root is not a chapter; top-level pages keep a bare title.
- if (!parent || parent.type !== "folder") return item;
+ const chapter = chapterName(tree, item.url);
+ if (!chapter) return item;
return {
...item,
name: (
<>
<span className="me-1 font-normal text-fd-muted-foreground">
- {parent.name}:
+ {chapter}:
</span>
{item.name}
</>
),
};
}
+
+// The title of the nearest parent folder, i.e. the chapter a page sits in.
+// Undefined for top-level pages, whose parent is the tree root and not a
+// chapter, and for the rare folder whose name is not a plain string.
+function chapterName(tree: PageTree.Root, url: string) {
+ const parent = PageTree.findParent(tree, url);
+ if (!parent || parent.type !== "folder") return undefined;
+ return typeof parent.name === "string" ? parent.name : undefined;
+}