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

bug: contentPath is required in order to correctly transform when collectionPathMode is root #47

Open
techfg opened this issue Apr 21, 2024 · 0 comments · May be fixed by #49
Open

bug: contentPath is required in order to correctly transform when collectionPathMode is root #47

techfg opened this issue Apr 21, 2024 · 0 comments · May be fixed by #49

Comments

@techfg
Copy link
Contributor

techfg commented Apr 21, 2024

When collectionPathMode='root', the contentPath option must be specified and point to the content collection that should be treated as the site root in order to transform a content collection to the site root.

For example, given the following directory structure & markdown file references:

.
├── src/
│   ├── content/
│   │   ├── blog/
│   │   |   ├── item-1.md/
│   │   |   ├── item-2.md/
│   │   ├── newsletter/
│   │   |   ├── item-1.md/
│   │   |   ├── item-2.md/

src/content/blog/item-1.md

[Blog Item 2](./item-2.md)

src/content/newsletter/item-1.md

[Newsletter Item 2](./item-2.md)

In order to have the blog content collection treated as site root, the following configuration is required:

{  
  collectionPathMode: 'root',
  contentPath: 'src/content/blog'
}

Repro: https://stackblitz.com/edit/withastro-astro-npyzr7
Steps to reproduce:

  1. Navigate to https://stackblitz.com/edit/withastro-astro-npyzr7
  2. Click on Blog Item 1 - Results in 404 because the transformed path is /blog/item-1.md
  3. Add contentPath: 'src/content/blog' to the plugin options in astro.config.mjs
  4. Repeat step 1 & 2

contentPath was added in v0.5.0 to support treating a content collection as the site root (see #2) so that the collection name was not prefixed to the transformed path. However, the contentPath option had some shortcomings:

  1. It did not handle all situations where the intended outcome was that the collection should be treated as site root (see issue bug: When contentPath is the same as the collectionPath, some transformed paths are incorrect #18 and PR fix: handle collections in root of site (#18) #19).
  2. It provided the ability for the user to specify a content directory which Astro does not allow, it is always ./content relative to the srcDir option. Beyond that, it creates unnecessary confusion because the contentPath points to a specific content collection whereas in Astro lingo, the content path should contain subdirectories of content collections.
  3. While multiple content collections would still work even with contentPath pointing to a specific content collection directory (because of relative paths), the option was applied to all content collections when it was intended to only identify one content collection as the site root.

When collectionPathMode was added in #19, it resolved the issues in #18, however it did not address the other two issues. With collectionPathMode in-place, there is no need for the contentPath to be specified and it should be removed. In its place, a srcDir option should be added to align with Astro's srcDir option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant