mirror of
https://github.com/Shik3i/KoalaSync.git
synced 2026-08-28 03:27:10 +00:00
fix: update sitemap dates for dirty sources
This commit is contained in:
@@ -85,7 +85,11 @@ for (const metadata of requiredSupportSocialMetadata) {
|
|||||||
}
|
}
|
||||||
if (!websiteBuild.includes("['log', '-1', '--format=%cs', '--', ...sourceFiles]")
|
if (!websiteBuild.includes("['log', '-1', '--format=%cs', '--', ...sourceFiles]")
|
||||||
|| !websiteBuild.includes("lastmod(['website/site-access-help.html'])")
|
|| !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');
|
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));
|
const documentedRelayUrls = [...llmsText.matchAll(/`(wss:\/\/[^`\s]+)`/g)].map(([, value]) => new URL(value));
|
||||||
|
|||||||
+51
-7
@@ -719,18 +719,61 @@ function generateSitemap(websiteDir, wwwDir) {
|
|||||||
|
|
||||||
const repoRoot = path.resolve(websiteDir, '..');
|
const repoRoot = path.resolve(websiteDir, '..');
|
||||||
const lastModifiedCache = new Map();
|
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) {
|
function getLastModified(sourceFiles) {
|
||||||
const cacheKey = sourceFiles.slice().sort().join('\0');
|
const cacheKey = sourceFiles.slice().sort().join('\0');
|
||||||
if (lastModifiedCache.has(cacheKey)) return lastModifiedCache.get(cacheKey);
|
if (lastModifiedCache.has(cacheKey)) return lastModifiedCache.get(cacheKey);
|
||||||
|
if (!gitHistoryAvailable) {
|
||||||
|
lastModifiedCache.set(cacheKey, null);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
let date = null;
|
let date = null;
|
||||||
try {
|
try {
|
||||||
const output = execFileSync(
|
if (sourceFiles.some(file => dirtySourceFiles.has(file))) {
|
||||||
'git',
|
usedDirtySourceDate = true;
|
||||||
['log', '-1', '--format=%cs', '--', ...sourceFiles],
|
date = new Date().toISOString().slice(0, 10);
|
||||||
{ cwd: repoRoot, encoding: 'utf8', stdio: ['ignore', 'pipe', 'ignore'] }
|
} else {
|
||||||
).trim();
|
const output = execFileSync(
|
||||||
if (/^\d{4}-\d{2}-\d{2}$/.test(output)) date = output;
|
'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 (_) {
|
} catch (_) {
|
||||||
// Source archives and minimal deployment environments may not contain
|
// Source archives and minimal deployment environments may not contain
|
||||||
// Git metadata. Omitting lastmod is more accurate than inventing a date.
|
// 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');
|
fs.writeFileSync(path.join(wwwDir, 'sitemap.xml'), xml.trim() + '\n', 'utf8');
|
||||||
const datedEntries = (xml.match(/<lastmod>/g) || []).length;
|
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); });
|
compile().catch(err => { console.error('Build failed:', err); process.exit(1); });
|
||||||
|
|||||||
Reference in New Issue
Block a user