Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
39 changes: 39 additions & 0 deletions site/scripts/pregnancy-hub-index-policy.test.mjs
Original file line number Diff line number Diff line change
@@ -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/);
});
13 changes: 9 additions & 4 deletions site/src/app/[locale]/pregnancy/page.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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}`,
Expand All @@ -63,7 +66,9 @@ export default async function PregnancyHub({ params }: { params: Promise<{ local

return (
<div className="mx-auto max-w-4xl px-4 py-10">
<script type="application/ld+json" dangerouslySetInnerHTML={{ __html: JSON.stringify(itemListLd) }} />
{indexableTools.length > 0 && (
<script type="application/ld+json" dangerouslySetInnerHTML={{ __html: JSON.stringify(itemListLd) }} />
)}

<h1 className="text-3xl font-bold">{t("pregnancy.title")}</h1>
<p className="mt-3 max-w-2xl text-slate-600 dark:text-slate-400">{t("pregnancy.intro")}</p>
Expand Down
Loading