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
1 change: 1 addition & 0 deletions .github/workflows/publish-production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ jobs:
name: Build
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ENABLE_LAST_MOD_IN_SITEMAP: true
- run: npx wrangler deploy
name: Deploy to Cloudflare Workers
env:
Expand Down
39 changes: 23 additions & 16 deletions astro.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import liveCode from "astro-live-code";
import starlightLinksValidator from "starlight-links-validator";
import starlightScrollToTop from "starlight-scroll-to-top";
import icon from "astro-icon";
import sitemap from "@astrojs/sitemap";
import sitemap, { type SitemapItem } from "@astrojs/sitemap";
import react from "@astrojs/react";

import { readdir } from "fs/promises";
Expand Down Expand Up @@ -59,7 +59,10 @@ async function autogenStyles() {
const sidebar = await autogenSections();
const customCss = await autogenStyles();

const runLinkCheck = process.env.RUN_LINK_CHECK || false;
const RUN_LINK_CHECK =
process.env.RUN_LINK_CHECK?.toLowerCase() === "true" || false;
const ENABLE_LAST_MOD_IN_SITEMAP =
process.env.ENABLE_LAST_MOD_IN_SITEMAP?.toLowerCase() === "true";

/**
* Get the last Git modification date for a file
Expand Down Expand Up @@ -107,6 +110,22 @@ function urlToFilePath(url: string): string | null {
}
}

function addLastModDate(item: SitemapItem) {
const filePath = urlToFilePath(item.url);
if (filePath) {
const gitDate = getGitLastModified(filePath);
if (gitDate) {
item.lastmod = gitDate;
}
} else {
console.warn(
`[sitemap] Could not find last modified for ${item.url} - setting to now`,
);
item.lastmod = new Date().toISOString();
}
return item;
}

// https://astro.build/config
export default defineConfig({
site: "https://developers.cloudflare.com",
Expand Down Expand Up @@ -176,7 +195,7 @@ export default defineConfig({
customCss,
pagination: false,
plugins: [
...(runLinkCheck
...(RUN_LINK_CHECK
? [
starlightLinksValidator({
errorOnInvalidHashes: false,
Expand Down Expand Up @@ -242,19 +261,7 @@ export default defineConfig({
return true;
},
serialize(item) {
const filePath = urlToFilePath(item.url);
if (filePath) {
const gitDate = getGitLastModified(filePath);
if (gitDate) {
item.lastmod = gitDate;
}
} else {
console.warn(
`[sitemap] Could not find last modified for ${item.url} - setting to now`,
);
item.lastmod = new Date().toISOString();
}
return item;
return ENABLE_LAST_MOD_IN_SITEMAP ? addLastModDate(item) : item;
},
}),
react(),
Expand Down
Loading