@@ -6,7 +6,7 @@ import liveCode from "astro-live-code";
66import starlightLinksValidator from "starlight-links-validator" ;
77import starlightScrollToTop from "starlight-scroll-to-top" ;
88import icon from "astro-icon" ;
9- import sitemap from "@astrojs/sitemap" ;
9+ import sitemap , { type SitemapItem } from "@astrojs/sitemap" ;
1010import react from "@astrojs/react" ;
1111
1212import { readdir } from "fs/promises" ;
@@ -59,7 +59,10 @@ async function autogenStyles() {
5959const sidebar = await autogenSections ( ) ;
6060const customCss = await autogenStyles ( ) ;
6161
62- const runLinkCheck = process . env . RUN_LINK_CHECK || false ;
62+ const RUN_LINK_CHECK =
63+ process . env . RUN_LINK_CHECK ?. toLowerCase ( ) === "true" || false ;
64+ const ENABLE_LAST_MOD_IN_SITEMAP =
65+ process . env . ENABLE_LAST_MOD_IN_SITEMAP ?. toLowerCase ( ) === "true" ;
6366
6467/**
6568 * Get the last Git modification date for a file
@@ -107,6 +110,22 @@ function urlToFilePath(url: string): string | null {
107110 }
108111}
109112
113+ function addLastModDate ( item : SitemapItem ) {
114+ const filePath = urlToFilePath ( item . url ) ;
115+ if ( filePath ) {
116+ const gitDate = getGitLastModified ( filePath ) ;
117+ if ( gitDate ) {
118+ item . lastmod = gitDate ;
119+ }
120+ } else {
121+ console . warn (
122+ `[sitemap] Could not find last modified for ${ item . url } - setting to now` ,
123+ ) ;
124+ item . lastmod = new Date ( ) . toISOString ( ) ;
125+ }
126+ return item ;
127+ }
128+
110129// https://astro.build/config
111130export default defineConfig ( {
112131 site : "https://developers.cloudflare.com" ,
@@ -176,7 +195,7 @@ export default defineConfig({
176195 customCss,
177196 pagination : false ,
178197 plugins : [
179- ...( runLinkCheck
198+ ...( RUN_LINK_CHECK
180199 ? [
181200 starlightLinksValidator ( {
182201 errorOnInvalidHashes : false ,
@@ -242,19 +261,7 @@ export default defineConfig({
242261 return true ;
243262 } ,
244263 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 ;
264+ return ENABLE_LAST_MOD_IN_SITEMAP ? addLastModDate ( item ) : item ;
258265 } ,
259266 } ) ,
260267 react ( ) ,
0 commit comments