fix: update sitemap dates for dirty sources

This commit is contained in:
Timo
2026-07-19 21:41:45 +02:00
parent 1149de7ab7
commit 5d3cee4271
2 changed files with 56 additions and 8 deletions
+5 -1
View File
@@ -85,7 +85,11 @@ for (const metadata of requiredSupportSocialMetadata) {
}
if (!websiteBuild.includes("['log', '-1', '--format=%cs', '--', ...sourceFiles]")
|| !websiteBuild.includes("lastmod(['website/site-access-help.html'])")
|| /const today = new Date\(\)/.test(websiteBuild)) {
|| !websiteBuild.includes("['rev-parse', '--is-shallow-repository']")
|| !websiteBuild.includes("['diff', '--name-only', '--']")
|| !websiteBuild.includes("['diff', '--cached', '--name-only', '--']")
|| !websiteBuild.includes("['ls-files', '--others', '--exclude-standard', '--']")
|| !websiteBuild.includes('sourceFiles.some(file => dirtySourceFiles.has(file))')) {
throw new Error('Sitemap lastmod values must come from the mapped source files in Git');
}
const documentedRelayUrls = [...llmsText.matchAll(/`(wss:\/\/[^`\s]+)`/g)].map(([, value]) => new URL(value));
+51 -7
View File
@@ -719,18 +719,61 @@ function generateSitemap(websiteDir, wwwDir) {
const repoRoot = path.resolve(websiteDir, '..');
const lastModifiedCache = new Map();
const dirtySourceFiles = new Set();
let gitHistoryAvailable = false;
let usedDirtySourceDate = false;
try {
const isInsideWorkTree = execFileSync(
'git', ['rev-parse', '--is-inside-work-tree'],
{ cwd: repoRoot, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }
).trim() === 'true';
const isShallow = execFileSync(
'git', ['rev-parse', '--is-shallow-repository'],
{ cwd: repoRoot, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }
).trim() === 'true';
gitHistoryAvailable = isInsideWorkTree && !isShallow;
if (gitHistoryAvailable) {
const dirtyCommands = [
['diff', '--name-only', '--'],
['diff', '--cached', '--name-only', '--'],
['ls-files', '--others', '--exclude-standard', '--']
];
for (const args of dirtyCommands) {
const output = execFileSync(
'git', args,
{ cwd: repoRoot, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }
);
for (const file of output.split(/\r?\n/).filter(Boolean)) {
dirtySourceFiles.add(file.replaceAll('\\', '/'));
}
}
}
} catch (_) {
gitHistoryAvailable = false;
}
function getLastModified(sourceFiles) {
const cacheKey = sourceFiles.slice().sort().join('\0');
if (lastModifiedCache.has(cacheKey)) return lastModifiedCache.get(cacheKey);
if (!gitHistoryAvailable) {
lastModifiedCache.set(cacheKey, null);
return null;
}
let date = null;
try {
const output = execFileSync(
'git',
['log', '-1', '--format=%cs', '--', ...sourceFiles],
{ cwd: repoRoot, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }
).trim();
if (/^\d{4}-\d{2}-\d{2}$/.test(output)) date = output;
if (sourceFiles.some(file => dirtySourceFiles.has(file))) {
usedDirtySourceDate = true;
date = new Date().toISOString().slice(0, 10);
} else {
const output = execFileSync(
'git',
['log', '-1', '--format=%cs', '--', ...sourceFiles],
{ cwd: repoRoot, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }
).trim();
if (/^\d{4}-\d{2}-\d{2}$/.test(output)) date = output;
}
} catch (_) {
// Source archives and minimal deployment environments may not contain
// Git metadata. Omitting lastmod is more accurate than inventing a date.
@@ -816,6 +859,7 @@ function generateSitemap(websiteDir, wwwDir) {
fs.writeFileSync(path.join(wwwDir, 'sitemap.xml'), xml.trim() + '\n', 'utf8');
const datedEntries = (xml.match(/<lastmod>/g) || []).length;
console.log(` ✓ Dynamically generated sitemap.xml with ${datedEntries} Git-derived modification dates`);
const dateSource = usedDirtySourceDate ? 'Git/working-tree-derived' : 'Git-derived';
console.log(` ✓ Dynamically generated sitemap.xml with ${datedEntries} ${dateSource} modification dates`);
}
compile().catch(err => { console.error('Build failed:', err); process.exit(1); });