Skip to content
Open
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
17 changes: 13 additions & 4 deletions scripts/deadLinkChecker.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,16 @@ const contributorMap = new Map(); // Map<anchorId, URL>
const redirectMap = new Map(); // Map<source, destination>
let errorCodes = new Set();

function normalizeFilePath(filePath) {
// Ensure we use a consistent, OS-native absolute path for Map keys.
// globby returns POSIX-style paths on Windows (e.g. C:/...), while path.join
// returns Windows-style paths (e.g. C:\...). Without normalization, anchor
// lookups fail on Windows.
return path.resolve(filePath);
}

async function readFileWithCache(filePath) {
filePath = normalizeFilePath(filePath);
if (!fileCache.has(filePath)) {
try {
const content = await fs.promises.readFile(filePath, 'utf8');
Expand Down Expand Up @@ -47,7 +56,7 @@ function getMarkdownFiles() {
path.posix.join(baseDir, '**/*.md'),
path.posix.join(baseDir, '**/*.mdx'),
];
return globby.sync(patterns);
return globby.sync(patterns).map(normalizeFilePath);
}

function extractAnchorsFromContent(content) {
Expand Down Expand Up @@ -80,7 +89,7 @@ async function buildAnchorMap(files) {
const content = await readFileWithCache(filePath);
const anchors = extractAnchorsFromContent(content);
if (anchors.size > 0) {
anchorMap.set(filePath, anchors);
anchorMap.set(normalizeFilePath(filePath), anchors);
}
}
}
Expand Down Expand Up @@ -135,7 +144,7 @@ async function findTargetFile(urlPath) {

for (const p of publicPaths) {
if (await fileExists(p)) {
return p;
return normalizeFilePath(p);
}
}
}
Expand All @@ -154,7 +163,7 @@ async function findTargetFile(urlPath) {

for (const p of possiblePaths) {
if (await fileExists(p)) {
return p;
return normalizeFilePath(p);
}
}
return null;
Expand Down