Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(astro): handle symlinked content collection directories #11236

Merged
merged 12 commits into from
Jun 12, 2024
Prev Previous commit
Next Next commit
Fix normalisation
  • Loading branch information
ascorbic committed Jun 12, 2024
commit fb08d4f878ef8b235600c23592b5a50c4492d7e1
11 changes: 6 additions & 5 deletions packages/astro/src/content/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,10 @@ export async function getSymlinkedContentCollections(
if (entry.isSymbolicLink()) {
const entryPath = path.join(contentDirPath, entry.name);
const realPath = await fsMod.promises.realpath(entryPath);
// Normalize path separators to posix to match Vite identifiers
contentPaths.set(realPath.split(path.sep).join(path.posix.sep), entry.name);
contentPaths.set(normalizePath(realPath), entry.name);
}
}
console.log({contentPaths });
console.log({ contentPaths });
return contentPaths;
}

Expand All @@ -199,15 +198,17 @@ export function reverseSymlinks({
contentDir: string | URL;
symlinks?: Map<string, string>;
}): string {
const entryPath = typeof entry === 'string' ? entry : fileURLToPath(entry);
const entryPath = normalizePath(typeof entry === 'string' ? entry : fileURLToPath(entry));
const contentDirPath = typeof contentDir === 'string' ? contentDir : fileURLToPath(contentDir);
if (!symlinks || symlinks.size === 0) {
return entryPath;
}

for (const [realPath, symlinkName] of symlinks) {
if (entryPath.startsWith(realPath)) {
return path.join(contentDirPath, symlinkName, entryPath.replace(realPath, ''));
const res = path.join(contentDirPath, symlinkName, entryPath.replace(realPath, ''));
console.log(`reverseSymlinks: ${entryPath} -> ${res}`);
return res;
}
}
return entryPath;
Expand Down
Loading