feat(web): hreflang alternates, sitemap.xml and robots.txt; staging noindex (MITHOME-116)

src/lib/seo.ts is the single source for page alternates (self canonical
+ hreflang hu/en/x-default), sitemap entries (every page in both
languages, with alternates) and robots rules. Per the user's decisions
every page is announced in both languages regardless of the English
approval status, and staging is never indexed: robots.txt disallows
all, the sitemap is empty and every page carries a noindex meta.

Home and catch-all page metadata now carry alternates and a locale-
correct og:url. Staging smoke SMOKE-09 checks hreflang, canonical,
noindex and robots.txt. Documented in architecture.md.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Do Siki
2026-09-29 12:36:12 +02:00
co-authored by Claude Opus 5.5
parent facc5db641
commit 2fd5c9bc8b
9 changed files with 162 additions and 4 deletions
+66
View File
@@ -0,0 +1,66 @@
/**
* MITHOME-116: hreflang alternates, sitemap entries and the staging
* indexing switch — one place so the page metadata, sitemap.xml and
* robots.txt can never disagree.
*
* DECISION (user): every page is announced in BOTH languages, regardless of
* the MITHOME-113 English approval status.
* DECISION (user): staging is never indexed (robots.txt disallows all, no
* sitemap, every page carries noindex).
*/
import type { MetadataRoute } from 'next'
import { siteConfig } from '@/config/site'
import { DEFAULT_LOCALE, LOCALES, PAGE_SLUGS, localePath, type Locale, type PageKey } from './i18n'
type SitePage = PageKey | undefined // undefined = home
const PAGES: readonly SitePage[] = [undefined, ...(Object.keys(PAGE_SLUGS) as PageKey[])]
function siteOrigin(siteUrl: string = siteConfig.general.url): string {
return siteUrl.replace(/\/+$/, '')
}
export function absoluteUrl(path: string, siteUrl?: string): string {
return `${siteOrigin(siteUrl)}${path}`
}
/** hreflang map for one page: every locale + x-default (the Hungarian page). */
export function languageAlternates(page: SitePage, siteUrl?: string): Record<string, string> {
const languages: Record<string, string> = Object.fromEntries(
LOCALES.map((locale) => [locale, absoluteUrl(localePath(locale, page), siteUrl)]),
)
return { ...languages, 'x-default': languages[DEFAULT_LOCALE] }
}
/** `alternates` for Next.js page metadata: self canonical + hreflang links. */
export function pageAlternates(locale: Locale, page: SitePage, siteUrl?: string) {
return {
canonical: absoluteUrl(localePath(locale, page), siteUrl),
languages: languageAlternates(page, siteUrl),
}
}
export function isIndexingDisabled(deployEnv: string | undefined = process.env.NEXT_PUBLIC_DEPLOY_ENV): boolean {
return deployEnv === 'staging'
}
export function sitemapEntries(siteUrl?: string): MetadataRoute.Sitemap {
return PAGES.flatMap((page) =>
LOCALES.map((locale) => ({
url: absoluteUrl(localePath(locale, page), siteUrl),
changeFrequency: 'monthly' as const,
priority: page === undefined ? 1 : page === 'privacy' || page === 'terms' ? 0.3 : 0.8,
alternates: { languages: languageAlternates(page, siteUrl) },
})),
)
}
export function robotsRules(deployEnv?: string, siteUrl?: string): MetadataRoute.Robots {
if (isIndexingDisabled(deployEnv)) {
return { rules: { userAgent: '*', disallow: '/' } }
}
return {
rules: { userAgent: '*', allow: '/', disallow: ['/admin', '/api/'] },
sitemap: absoluteUrl('/sitemap.xml', siteUrl),
}
}