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

UnknownContentCollectionError when Soft Links Used in Content Collections #8262

Open
1 task done
equt opened this issue Aug 29, 2023 · 3 comments
Open
1 task done
Labels
- P2: has workaround Bug, but has workaround (priority) feat: content collections Related to the Content Collections feature (scope)

Comments

@equt
Copy link
Contributor

equt commented Aug 29, 2023

Astro info

Astro version            v2.10.14
Package manager          npm
Platform                 darwin
Architecture             arm64
Adapter                  Couldn't determine.
Integrations             None or couldn't determine.

What browser are you using?

Chrome

Describe the Bug

  1. Create a collection, either in data or in content
  2. Soft link files or entire directory into the src/content directory
  3. Query that collection

What's the expected result?

It should work as normal

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-x2fbkv?file=src%2Fpages%2Findex.astro&on=stackblitz

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Aug 29, 2023
@equt
Copy link
Contributor Author

equt commented Aug 29, 2023

I can't figure out a way to create a real soft link in the above reproducible sandbox. But the problem is caused by the

export function getEntryCollectionName({
contentDir,
entry,
}: Pick<ContentPaths, 'contentDir'> & { entry: string | URL }) {
const entryPath = typeof entry === 'string' ? entry : fileURLToPath(entry);
const rawRelativePath = path.relative(fileURLToPath(contentDir), entryPath);
const collectionName = path.dirname(rawRelativePath).split(path.sep)[0];
const isOutsideCollection =
!collectionName || collectionName === '' || collectionName === '..' || collectionName === '.';
if (isOutsideCollection) {
return undefined;
}
return collectionName;
}

This utility function will parse the collection name out of the entry, which comes from the fileId. Unfortunately, Vite will resolve the (link) path before Astro ever has a chance to read the it.

@natemoo-re
Copy link
Member

Yep, this makes sense and it seems like we should support it! Probably didn't account for symlinks.

@natemoo-re natemoo-re added - P3: minor bug An edge case that only affects very specific usage (priority) feat: content collections Related to the Content Collections feature (scope) labels Aug 31, 2023
@github-actions github-actions bot removed the needs triage Issue needs to be triaged label Aug 31, 2023
@YonicDev
Copy link

YonicDev commented Nov 1, 2023

While tackling this I found out that there's an option for Vite to preserve soft links when resolving.
Add the following config in astro.config.mjs and it should work:

export default defineConfig({
  vite: {
    resolve: {
      preserveSymlinks: true
    }
  }
})

@florian-lefebvre florian-lefebvre added - P2: has workaround Bug, but has workaround (priority) and removed - P3: minor bug An edge case that only affects very specific usage (priority) labels Jan 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- P2: has workaround Bug, but has workaround (priority) feat: content collections Related to the Content Collections feature (scope)
Projects
None yet
Development

No branches or pull requests

4 participants