Skip to content

Commit c522404

Browse files
wharfeclaude
andcommitted
fix: add lastmod dates to sitemap for better Google indexing
Populate lastmod from actual data (diff dates, timeline enforcement dates) so Google can prioritize crawling. Addresses 14 pages showing as "not indexed" in Search Console. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 61a3e2b commit c522404

1 file changed

Lines changed: 45 additions & 13 deletions

File tree

frontend/app/sitemap.ts

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import type { MetadataRoute } from "next";
2-
import { getDiffIds, getTimelineIds } from "@/lib/data";
2+
import {
3+
getDiffIds,
4+
getDiffData,
5+
getTimelineIds,
6+
getTimelineData,
7+
} from "@/lib/data";
38
import { LIFE_THEMES } from "@/lib/life-themes";
49

510
export const dynamic = "force-static";
@@ -11,28 +16,55 @@ export default function sitemap(): MetadataRoute.Sitemap {
1116
const lawIds = getTimelineIds();
1217
const themeIds = LIFE_THEMES.map((t) => t.id);
1318

19+
// Compute the most recent diff date for the home page lastmod
20+
const allDiffDates = diffIds.map((id) => getDiffData(id).date_after);
21+
const latestDiffDate =
22+
allDiffDates.length > 0
23+
? allDiffDates.sort().reverse()[0]
24+
: new Date().toISOString().slice(0, 10);
25+
1426
return [
1527
// Static pages
16-
{ url: BASE_URL, changeFrequency: "weekly", priority: 1.0 },
17-
{ url: `${BASE_URL}/about`, changeFrequency: "monthly", priority: 0.5 },
28+
{
29+
url: BASE_URL,
30+
lastModified: latestDiffDate,
31+
changeFrequency: "weekly",
32+
priority: 1.0,
33+
},
34+
{
35+
url: `${BASE_URL}/about`,
36+
changeFrequency: "monthly",
37+
priority: 0.5,
38+
},
1839

1940
// Law pages (from timeline data)
20-
...lawIds.map((id) => ({
21-
url: `${BASE_URL}/law/${id}`,
22-
changeFrequency: "weekly" as const,
23-
priority: 0.8,
24-
})),
41+
...lawIds.map((id) => {
42+
const data = getTimelineData(id);
43+
// Timeline is sorted newest-first; use the first entry as lastmod
44+
const latestEntry = data.timeline[0];
45+
return {
46+
url: `${BASE_URL}/law/${id}`,
47+
lastModified: latestEntry?.enforcement_date,
48+
changeFrequency: "weekly" as const,
49+
priority: 0.8,
50+
};
51+
}),
2552

2653
// Diff pages (from diff data files)
27-
...diffIds.map((id) => ({
28-
url: `${BASE_URL}/diff/${id}`,
29-
changeFrequency: "monthly" as const,
30-
priority: 0.7,
31-
})),
54+
...diffIds.map((id) => {
55+
const data = getDiffData(id);
56+
return {
57+
url: `${BASE_URL}/diff/${id}`,
58+
lastModified: data.date_after,
59+
changeFrequency: "monthly" as const,
60+
priority: 0.7,
61+
};
62+
}),
3263

3364
// Theme pages (from life-themes config)
3465
...themeIds.map((id) => ({
3566
url: `${BASE_URL}/theme/${id}`,
67+
lastModified: latestDiffDate,
3668
changeFrequency: "weekly" as const,
3769
priority: 0.6,
3870
})),

0 commit comments

Comments
 (0)