Page title generator on browser tab rebuilded.

This commit is contained in:
2026-09-08 14:25:15 +02:00
parent e16a18e488
commit 781e348ded
8 changed files with 128 additions and 19 deletions
+16 -11
View File
@@ -9,13 +9,16 @@ import { buildHreflangAlternates } from './hreflang.js';
* Designed for use inside Next.js `generateMetadata`. The caller resolves the
* pieces (meta group, site name, image URL, localized slugs) and passes them
* in — the plugin composes, it doesn't fetch.
*/ export function buildMetadata({ baseUrl, config, homeSlug = 'home', imageUrl, locale, meta, order, prefix, query, separator, siteName, slugs }) {
// titleOverride wins outright: an editor who filled it in wants that exact
// string in the tab, not a composition.
*/ export function buildMetadata({ baseUrl, config, homeSlug = 'home', imageUrl, locale, meta, order, pageTitle, prefix, query, separator, siteName, slugs }) {
// Title source priority: titleOverride (exact, wins outright) > meta.title
// (SEO title an editor set) > pageTitle (the document's own name). This means
// a page with no SEO title still shows its name (e.g. 'Sprzątanie biur')
// composed with the site name, instead of just the site name or a blank.
const override = meta?.titleOverride?.trim();
const resolvedPageTitle = meta?.title?.trim() || pageTitle?.trim() || undefined;
const title = override || composeTitle({
order,
pageTitle: meta?.title,
pageTitle: resolvedPageTitle,
separator,
siteName
});
@@ -60,12 +63,6 @@ import { buildHreflangAlternates } from './hreflang.js';
languages
}
},
...meta?.noindex ? {
robots: {
follow: true,
index: false
}
} : {},
openGraph: {
title,
...description && {
@@ -75,7 +72,15 @@ import { buildHreflangAlternates } from './hreflang.js';
images
},
locale
}
},
// noindex → tell search engines to exclude the page but still follow links
// (authority flows through). For legal/thin/search-result pages.
...meta?.noindex ? {
robots: {
follow: true,
index: false
}
} : {}
};
}