diff --git a/.agent/steering/architecture.md b/.agent/steering/architecture.md index 244ce54..54697cf 100644 --- a/.agent/steering/architecture.md +++ b/.agent/steering/architecture.md @@ -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 diff --git a/proto/e2e/staging-smoke.spec.ts b/proto/e2e/staging-smoke.spec.ts index dca5a02..e0a40cf 100644 --- a/proto/e2e/staging-smoke.spec.ts +++ b/proto/e2e/staging-smoke.spec.ts @@ -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 => { diff --git a/proto/src/app/(frontend)/[locale]/[slug]/page.tsx b/proto/src/app/(frontend)/[locale]/[slug]/page.tsx index f76740a..0a8fb3b 100644 --- a/proto/src/app/(frontend)/[locale]/[slug]/page.tsx +++ b/proto/src/app/(frontend)/[locale]/[slug]/page.tsx @@ -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 }): 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') { diff --git a/proto/src/app/(frontend)/[locale]/page.tsx b/proto/src/app/(frontend)/[locale]/page.tsx index dcc08d0..0f726bc 100755 --- a/proto/src/app/(frontend)/[locale]/page.tsx +++ b/proto/src/app/(frontend)/[locale]/page.tsx @@ -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 }): 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), } } diff --git a/proto/src/app/(frontend)/layout.tsx b/proto/src/app/(frontend)/layout.tsx index a402d50..657ce92 100755 --- a/proto/src/app/(frontend)/layout.tsx +++ b/proto/src/app/(frontend)/layout.tsx @@ -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. diff --git a/proto/src/app/robots.ts b/proto/src/app/robots.ts new file mode 100644 index 0000000..a26fd4c --- /dev/null +++ b/proto/src/app/robots.ts @@ -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() +} diff --git a/proto/src/app/sitemap.ts b/proto/src/app/sitemap.ts new file mode 100644 index 0000000..09b65bb --- /dev/null +++ b/proto/src/app/sitemap.ts @@ -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() +} diff --git a/proto/src/lib/seo.test.ts b/proto/src/lib/seo.test.ts new file mode 100644 index 0000000..a8771c7 --- /dev/null +++ b/proto/src/lib/seo.test.ts @@ -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', + }) + }) +}) diff --git a/proto/src/lib/seo.ts b/proto/src/lib/seo.ts new file mode 100644 index 0000000..b313b87 --- /dev/null +++ b/proto/src/lib/seo.ts @@ -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 { + const languages: Record = 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), + } +}