diff --git a/site/package.json b/site/package.json index 3769b038..02bca82d 100644 --- a/site/package.json +++ b/site/package.json @@ -9,7 +9,7 @@ "lint": "next lint", "typecheck": "tsc --noEmit", "fetch:rates": "tsx scripts/fetch-rates.ts", - "prebuild": "node --test scripts/workdays-faq-parity.test.mjs && node --test scripts/sharebar-state-navigation.test.mjs && node scripts/check-site-url.mjs && tsx scripts/fetch-rates.ts && node scripts/check-pressure-reference.mjs && node scripts/check-currency-rate-freshness.mjs", + "prebuild": "node --test scripts/workdays-faq-parity.test.mjs && node --test scripts/sharebar-state-navigation.test.mjs && node --test scripts/pregnancy-hub-index-policy.test.mjs && node scripts/check-site-url.mjs && tsx scripts/fetch-rates.ts && node scripts/check-pressure-reference.mjs && node scripts/check-currency-rate-freshness.mjs", "sitemap": "tsx scripts/generate-sitemap.ts", "validate": "tsx scripts/validate.ts", "audit:seo": "tsx scripts/audit-seo.ts", diff --git a/site/scripts/pregnancy-hub-index-policy.test.mjs b/site/scripts/pregnancy-hub-index-policy.test.mjs new file mode 100644 index 00000000..59728def --- /dev/null +++ b/site/scripts/pregnancy-hub-index-policy.test.mjs @@ -0,0 +1,39 @@ +import test from "node:test"; +import assert from "node:assert/strict"; +import { readFileSync } from "node:fs"; + +const read = path => readFileSync(new URL(path, import.meta.url), "utf8"); +const hub = read("../src/app/[locale]/pregnancy/page.tsx"); +const tools = read("../src/lib/tools/registry.ts"); +const locales = read("../src/lib/i18n/locales.ts"); +const sitemap = read("../src/app/sitemap.ts"); + +test("pregnancy hub keeps all seven actual utility steps for visitors", () => { + const match = hub.match(/const CLUSTER = \[([\s\S]*?)\] as const;/); + assert.ok(match, "tool journey CLUSTER missing"); + const slugs = [...match[1].matchAll(/"([a-z-]+)"/g)].map(m => m[1]); + assert.deepEqual(slugs, [ + "menstrual-cycle-calculator", "ovulation-calculator", + "conception-date-calculator", "due-date-calculator", + "pregnancy-week-calculator", "pregnancy-weight-gain-calculator", + "hcg-calculator", + ]); + assert.match(hub, /tools\.map\(\(m, i\) =>/); // Visible journey is not pruned. +}); + +test("published pregnancy ItemList only describes locally indexable URLs", () => { + assert.match(hub, /import \{ getTool, isIndexableIn \} from "@\/lib\/tools\/registry";/); + assert.match(hub, /const indexableTools = tools\.filter\(\(tool\) => isIndexableIn\(locale, tool\.slug\)\);/); + assert.match(hub, /numberOfItems: indexableTools\.length/); + assert.match(hub, /itemListElement: indexableTools\.map\(/); + assert.match(hub, /\{indexableTools\.length > 0 && \(/); + assert.match(tools, /export function isIndexableIn\(locale: string, slug: string\): boolean/); +}); + +test("locale-indexing policy and sitemap use the same source of truth", () => { + assert.match(locales, /export const INDEXED_LOCALES: Locale\[\] = \["en", "ja"\];/); + assert.match(tools, /if \(INDEXED_SLUGS\.has\(slug\) && isIndexedLocale\(locale\)\) return true;/); + assert.match(tools, /INDEX_EXCEPTIONS\[locale\]\?\.includes\(slug\)/); + assert.match(sitemap, /indexableLocalesFor\(tool\.slug\)/); + assert.match(sitemap, /listIndexableByCategory\(c\)\.length > 0/); +}); diff --git a/site/src/app/[locale]/pregnancy/page.tsx b/site/src/app/[locale]/pregnancy/page.tsx index 09c327fa..176a2705 100644 --- a/site/src/app/[locale]/pregnancy/page.tsx +++ b/site/src/app/[locale]/pregnancy/page.tsx @@ -1,7 +1,7 @@ import type { Metadata } from "next"; import { setRequestLocale, getTranslations } from "next-intl/server"; import { buildMetadata } from "@/lib/seo/metadata"; -import { getTool } from "@/lib/tools/registry"; +import { getTool, isIndexableIn } from "@/lib/tools/registry"; import { ToolCard } from "@/components/tools/ToolCard"; import { siteConfig } from "@/lib/config"; import type { Locale } from "@/lib/i18n/locales"; @@ -47,13 +47,16 @@ export default async function PregnancyHub({ params }: { params: Promise<{ local setRequestLocale(locale); const t = await getTranslations(); const tools = CLUSTER.map((slug) => getTool(slug)).filter(Boolean) as ToolMeta[]; + // Keep the seven-step user journey, but never advertise deliberate noindex + // destinations as Google ItemList results on this crawlable hub. + const indexableTools = tools.filter((tool) => isIndexableIn(locale, tool.slug)); const itemListLd = { "@context": "https://schema.org", "@type": "ItemList", name: t("pregnancy.title"), - numberOfItems: tools.length, - itemListElement: tools.map((m, i) => ({ + numberOfItems: indexableTools.length, + itemListElement: indexableTools.map((m, i) => ({ "@type": "ListItem", position: i + 1, url: `${siteConfig.url}/${locale}/tools/${m.slug}`, @@ -63,7 +66,9 @@ export default async function PregnancyHub({ params }: { params: Promise<{ local return (
-