Skip to content

Commit afa071e

Browse files
committed
feat: only add lastmod during CI build
1 parent 6096032 commit afa071e

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

astro.config.ts

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import liveCode from "astro-live-code";
66
import starlightLinksValidator from "starlight-links-validator";
77
import starlightScrollToTop from "starlight-scroll-to-top";
88
import icon from "astro-icon";
9-
import sitemap from "@astrojs/sitemap";
9+
import sitemap, { type SitemapItem } from "@astrojs/sitemap";
1010
import react from "@astrojs/react";
1111

1212
import { readdir } from "fs/promises";
@@ -59,7 +59,9 @@ async function autogenStyles() {
5959
const sidebar = await autogenSections();
6060
const customCss = await autogenStyles();
6161

62-
const runLinkCheck = process.env.RUN_LINK_CHECK || false;
62+
const runLinkCheck =
63+
process.env.RUN_LINK_CHECK?.toLowerCase() === "true" || false;
64+
const IS_CI = process.env.CI?.toLowerCase() === "true";
6365

6466
/**
6567
* Get the last Git modification date for a file
@@ -107,6 +109,22 @@ function urlToFilePath(url: string): string | null {
107109
}
108110
}
109111

112+
function addLastModDate(item: SitemapItem) {
113+
const filePath = urlToFilePath(item.url);
114+
if (filePath) {
115+
const gitDate = getGitLastModified(filePath);
116+
if (gitDate) {
117+
item.lastmod = gitDate;
118+
}
119+
} else {
120+
console.warn(
121+
`[sitemap] Could not find last modified for ${item.url} - setting to now`,
122+
);
123+
item.lastmod = new Date().toISOString();
124+
}
125+
return item;
126+
}
127+
110128
// https://astro.build/config
111129
export default defineConfig({
112130
site: "https://developers.cloudflare.com",
@@ -242,19 +260,7 @@ export default defineConfig({
242260
return true;
243261
},
244262
serialize(item) {
245-
const filePath = urlToFilePath(item.url);
246-
if (filePath) {
247-
const gitDate = getGitLastModified(filePath);
248-
if (gitDate) {
249-
item.lastmod = gitDate;
250-
}
251-
} else {
252-
console.warn(
253-
`[sitemap] Could not find last modified for ${item.url} - setting to now`,
254-
);
255-
item.lastmod = new Date().toISOString();
256-
}
257-
return item;
263+
return IS_CI ? addLastModDate(item) : item;
258264
},
259265
}),
260266
react(),

0 commit comments

Comments
 (0)