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
+6
View File
@@ -54,6 +54,12 @@ A projekt egy **Next.js 15 alapú marketing weboldal** a mozdIT Bt. számára, A
- Animációk: `globals.css`-ben definiált utility osztályok (`.card`, `.btn`, `.icon-container`)
- Reszponzivitás: mobile-first, breakpoint-ok: 360px, 640px, 768px, 1024px, 1280px+
## SEO (MITHOME-116)
- Minden publikus oldal `generateMetadata`-ja `alternates: pageAlternates(locale, pageKey)`-t ad: saját canonical + hreflang `hu`/`en`/`x-default` (a magyar oldal). Új oldal felvételekor a `PAGE_SLUGS`-ba kell tenni, így a sitemapbe és a hreflang-párokba is automatikusan bekerül (`proto/src/lib/seo.ts`).
- `/sitemap.xml` és `/robots.txt` a `proto/src/app/sitemap.ts` és `robots.ts` fájlból jön. Felhasználói döntés: minden oldal mindkét nyelve szerepel, az angol jóváhagyási állapottól (MITHOME-113) függetlenül.
- A staging (`NEXT_PUBLIC_DEPLOY_ENV=staging`) sosem indexelhető: a `robots.txt` mindent tilt, a sitemap üres, és minden oldal `noindex` metát kap. A `NEXT_PUBLIC_*` értékek build időben égnek be, ezért a site URL-nek és a deploy-környezetnek build-argumentumként is meg kell lennie (Dockerfile).
## Content Management
```typescript
+15
View File
@@ -85,6 +85,21 @@ test('SMOKE-08: language switcher opens the same page in the other language', as
await expect(page.getByRole('group', { name: 'Choose language' }).first().getByRole('link', { name: 'Magyar' })).toHaveAttribute('href', '/hu/szolgaltatasok')
})
// MITHOME-116: pages announce both languages (hreflang), and staging is
// never indexed (disallow-all robots.txt, empty sitemap, noindex meta).
test('SMOKE-09: hreflang alternates and staging noindex', async ({ page, request }) => {
await page.goto('/hu/szolgaltatasok')
const origin = new URL(page.url()).origin
await expect(page.locator('link[rel="alternate"][hreflang="en"]')).toHaveAttribute('href', `${origin}/en/services`)
await expect(page.locator('link[rel="alternate"][hreflang="x-default"]')).toHaveAttribute('href', `${origin}/hu/szolgaltatasok`)
await expect(page.locator('link[rel="canonical"]')).toHaveAttribute('href', `${origin}/hu/szolgaltatasok`)
await expect(page.locator('meta[name="robots"]')).toHaveAttribute('content', /noindex/)
const robots = await (await request.get('/robots.txt')).text()
expect(robots).toMatch(/Disallow: \/\s*$/m)
expect(robots).not.toContain('Sitemap:')
})
test('SMOKE-05: empty contact form is blocked client-side without API submission', async ({ page }) => {
let contactPostCount = 0
page.on('request', request => {
@@ -4,7 +4,8 @@ import AboutView from '@/components/views/AboutView'
import ServicesView from '@/components/views/ServicesView'
import ContactView from '@/components/views/ContactView'
import LegalPageView from '@/components/views/LegalPageView'
import { resolvePageKey, isLocale, type Locale } from '@/lib/i18n'
import { resolvePageKey, isLocale, localePath, type Locale } from '@/lib/i18n'
import { absoluteUrl, pageAlternates } from '@/lib/seo'
import {
getAboutContent,
getServicesContent,
@@ -45,9 +46,11 @@ export async function generateMetadata({ params }: { params: Promise<Params> }):
openGraph: {
title: `${title} | ${siteConfig.general.name}`,
description: ogDescription,
url: `${siteConfig.general.url}${'/' + locale}/${slug}`,
url: absoluteUrl(localePath(locale, key)),
locale: getOgLocale(locale),
},
// MITHOME-116: self canonical + hreflang pairs (hu, en, x-default).
alternates: pageAlternates(locale, key),
})
if (key === 'about') {
+5 -2
View File
@@ -1,6 +1,7 @@
import type { Metadata } from 'next'
import HomeView from '@/components/views/HomeView'
import { isLocale, type Locale } from '@/lib/i18n'
import { isLocale, localePath, type Locale } from '@/lib/i18n'
import { absoluteUrl, pageAlternates } from '@/lib/seo'
import { getHomeContent, getPartners } from '@/lib/payload-content'
import { siteConfig, getSiteDescription, getOgLocale } from '@/config/site'
import { notFound } from 'next/navigation'
@@ -21,12 +22,14 @@ export async function generateMetadata({ params }: { params: Promise<Params> }):
openGraph: {
title: siteConfig.general.name,
description,
url: siteConfig.general.url,
url: absoluteUrl(localePath(locale)),
siteName: siteConfig.general.name,
images: [{ url: siteConfig.general.ogImage, width: 1200, height: 630, alt: siteConfig.general.name }],
locale: getOgLocale(locale),
type: 'website',
},
// MITHOME-116: self canonical + hreflang pairs (hu, en, x-default).
alternates: pageAlternates(locale, undefined),
}
}
+4
View File
@@ -4,6 +4,7 @@ import "./globals.css";
import { ThemeProvider } from "../../components/ThemeProvider";
import { siteConfig, getSiteDescription } from "../../config/site";
import { isIndexingDisabled } from "../../lib/seo";
const geistSans = Geist({
variable: "--font-geist-sans",
@@ -27,6 +28,9 @@ export const metadata: Metadata = {
title: siteConfig.general.name,
description: getSiteDescription("hu"),
authors: [{ name: siteConfig.general.name }],
// MITHOME-116 (user decision): staging must never be indexed — noindex on
// every page, on top of the disallow-all robots.txt.
...(isIndexingDisabled() ? { robots: { index: false, follow: false } } : {}),
};
// Keep Safari's browser chrome neutral; only the in-page staging strip is amber.
+8
View File
@@ -0,0 +1,8 @@
import type { MetadataRoute } from 'next'
import { robotsRules } from '@/lib/seo'
// MITHOME-116: /robots.txt — production allows crawling (except admin/API)
// and points to the sitemap; staging disallows everything.
export default function robots(): MetadataRoute.Robots {
return robotsRules()
}
+8
View File
@@ -0,0 +1,8 @@
import type { MetadataRoute } from 'next'
import { isIndexingDisabled, sitemapEntries } from '@/lib/seo'
// MITHOME-116: /sitemap.xml — every page in hu + en with hreflang alternates.
// Staging publishes no sitemap (DECISION: staging is never indexed).
export default function sitemap(): MetadataRoute.Sitemap {
return isIndexingDisabled() ? [] : sitemapEntries()
}
+45
View File
@@ -0,0 +1,45 @@
import { absoluteUrl, isIndexingDisabled, pageAlternates, robotsRules, sitemapEntries } from './seo'
const SITE = 'https://mozdit.hu/'
describe('SEO helpers (MITHOME-116)', () => {
it('should build absolute URLs without double slashes', () => {
expect(absoluteUrl('/hu/rolunk', SITE)).toBe('https://mozdit.hu/hu/rolunk')
})
it('should give each page a self canonical and hreflang pairs with x-default', () => {
expect(pageAlternates('en', 'services', SITE)).toEqual({
canonical: 'https://mozdit.hu/en/services',
languages: {
hu: 'https://mozdit.hu/hu/szolgaltatasok',
en: 'https://mozdit.hu/en/services',
'x-default': 'https://mozdit.hu/hu/szolgaltatasok',
},
})
expect(pageAlternates('hu', undefined, SITE).languages).toEqual({
hu: 'https://mozdit.hu/hu',
en: 'https://mozdit.hu/en',
'x-default': 'https://mozdit.hu/hu',
})
})
it('should list every page in both languages in the sitemap', () => {
const entries = sitemapEntries(SITE)
expect(entries).toHaveLength(12)
expect(entries.map((e) => e.url)).toEqual(
expect.arrayContaining(['https://mozdit.hu/hu', 'https://mozdit.hu/en', 'https://mozdit.hu/en/privacy-policy', 'https://mozdit.hu/hu/felhasznalasi-feltetelek']),
)
const privacy = entries.find((e) => e.url.endsWith('/en/privacy-policy'))!
expect(privacy.alternates?.languages).toMatchObject({ hu: 'https://mozdit.hu/hu/adatvedelem' })
})
it('should block all crawling on staging and publish the sitemap elsewhere', () => {
expect(isIndexingDisabled('staging')).toBe(true)
expect(isIndexingDisabled(undefined)).toBe(false)
expect(robotsRules('staging', SITE)).toEqual({ rules: { userAgent: '*', disallow: '/' } })
expect(robotsRules(undefined, SITE)).toEqual({
rules: { userAgent: '*', allow: '/', disallow: ['/admin', '/api/'] },
sitemap: 'https://mozdit.hu/sitemap.xml',
})
})
})
+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),
}
}