SEO: multilingual homepage (homeSlug per locale in path/sitemap), Article + llms.txt generators, siteDescription fallback, composeTitle dedup

This commit is contained in:
2026-09-15 15:31:08 +02:00
parent 87d575f335
commit 33ae035adc
25 changed files with 398 additions and 61 deletions
+25 -21
View File
@@ -1,18 +1,15 @@
import type { BasePayload } from 'payload'
import type { TitleOrder } from './composeTitle.js'
type SettingsShape = {
homepage?: { id: string | number; slug?: unknown } | string | number | null
titleSeparator?: string | null
titleOrder?: TitleOrder | null
[key: string]: unknown
homepage?: { id: number | string; slug?: unknown } | null | number | string
titleOrder?: null | TitleOrder
titleSeparator?: null | string
}
export type SiteMetaConfig = {
siteName: string | null
/** Padded separator, e.g. ' | ' — the panel stores the bare character. */
separator?: string
order?: TitleOrder
/**
* Home slug per locale, e.g. { pl: 'strona-glowna', de: 'startseite' }. A map
* (not a single string) so multilingual homepages collapse to root in EVERY
@@ -20,6 +17,12 @@ export type SiteMetaConfig = {
* instead of '/de', breaking return tags (a real GSC error).
*/
homeSlug?: Record<string, string>
order?: TitleOrder
/** Padded separator, e.g. ' | ' — the panel stores the bare character. */
separator?: string
/** Global fallback meta description. */
siteDescription?: null | string
siteName: null | string
}
/**
@@ -31,13 +34,13 @@ export type SiteMetaConfig = {
* relationship — it should receive a resolved config.
*/
export async function readSiteMetaConfig({
payload,
locale,
settingsSlug = 'site-settings',
siteNameField = 'siteName',
}: {
payload: BasePayload
locale,
payload,
settingsSlug = 'site-settings',
siteNameField = 'siteName',
}: {
locale: string
payload: BasePayload
settingsSlug?: string
siteNameField?: string
}): Promise<SiteMetaConfig> {
@@ -45,8 +48,8 @@ export async function readSiteMetaConfig({
// without a second query.
const settings = (await payload.findGlobal({
slug: settingsSlug as never,
locale: locale as never,
depth: 1,
locale: locale as never,
})) as SettingsShape
const homepage =
@@ -60,18 +63,18 @@ export async function readSiteMetaConfig({
if (homepage?.id) {
try {
const homeDoc = (await payload.findByID({
collection: 'pages' as never,
id: homepage.id,
locale: 'all' as never,
collection: 'pages' as never,
depth: 0,
locale: 'all' as never,
})) as { slug?: unknown }
const slugField = homeDoc.slug
if (slugField && typeof slugField === 'object') {
const map: Record<string, string> = {}
for (const [loc, value] of Object.entries(slugField as Record<string, unknown>)) {
if (typeof value === 'string') map[loc] = value
if (typeof value === 'string') {map[loc] = value}
}
if (Object.keys(map).length > 0) homeSlug = map
if (Object.keys(map).length > 0) {homeSlug = map}
} else if (typeof slugField === 'string') {
// Non-localized slug (same in every language) — key it by current locale;
// buildLocalizedPath tolerates a partial map. Non-localized homepage
@@ -90,10 +93,11 @@ export async function readSiteMetaConfig({
}
return {
siteDescription: (settings.siteDescription as string | undefined) ?? null,
siteName: (settings[siteNameField] as string | undefined) ?? null,
// The panel stores '|'; titles need it padded.
separator: settings.titleSeparator ? ` ${settings.titleSeparator} ` : undefined,
order: settings.titleOrder ?? undefined,
homeSlug,
order: settings.titleOrder ?? undefined,
separator: settings.titleSeparator ? ` ${settings.titleSeparator} ` : undefined,
}
}
}