Skip to content

Commit 348bab3

Browse files
committed
fix(seo): use git commit dates for dateModified instead of build date
Replace new Date().toISOString() with git log timestamps so dateModified in TechArticle JSON-LD reflects actual content changes rather than claiming every page was modified on each deploy.
1 parent 82f418e commit 348bab3

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

website/src/layouts/DocsPage.astro

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ interface Props {
77
}
88
99
import BaseLayout from "./BaseLayout.astro";
10+
import { execSync } from "node:child_process";
1011
1112
const props = Astro.props;
1213
const title = props.title ?? props.frontmatter?.title ?? '';
@@ -36,6 +37,20 @@ const siteOrigin = "https://useprimer.dev";
3637
const pagePath = Astro.url.pathname.replace(/\/$/, "") || "/";
3738
const pageUrl = `${siteOrigin}${pagePath}/`;
3839
40+
function getGitDateModified(pathname: string): string {
41+
try {
42+
const slug = pathname.replace(/^\//, "").replace(/\/$/, "");
43+
const gitRoot = execSync("git rev-parse --show-toplevel", { encoding: "utf-8" }).trim();
44+
const candidates = [`${gitRoot}/website/src/pages/${slug}.mdx`, `${gitRoot}/website/src/pages/${slug}.md`, `${gitRoot}/website/src/pages/${slug}.astro`];
45+
for (const filePath of candidates) {
46+
const ts = execSync(`git log -1 --format=%aI -- "${filePath}"`, { encoding: "utf-8" }).trim();
47+
if (ts) return ts.split("T")[0];
48+
}
49+
} catch { /* ignore */ }
50+
return new Date().toISOString().split("T")[0];
51+
}
52+
const dateModified = getGitDateModified(pagePath);
53+
3954
// Two-level breadcrumb (Documentation → page). We don't include the
4055
// frontmatter `section` tier because the docs index uses different
4156
// section groupings than the frontmatter, so there's no real landing
@@ -48,7 +63,7 @@ const structuredData = [
4863
headline: title,
4964
description,
5065
inLanguage: "en",
51-
dateModified: new Date().toISOString().split("T")[0],
66+
dateModified,
5267
author: { "@type": "Organization", name: "Primer", url: siteOrigin },
5368
isPartOf: { "@type": "WebSite", name: "Primer Documentation", url: `${siteOrigin}/docs/` },
5469
mainEntityOfPage: { "@type": "WebPage", "@id": pageUrl },

0 commit comments

Comments
 (0)