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

Content Layer based collections do not exclude pages starting with underscore (_) #12730

Closed
1 task
techfg opened this issue Dec 13, 2024 · 3 comments
Closed
1 task
Labels
needs triage Issue needs to be triaged

Comments

@techfg
Copy link

techfg commented Dec 13, 2024

Astro Info

Astro                    v5.0.5
Node                     v18.20.3
System                   Linux (x64)
Package Manager          unknown
Output                   static
Adapter                  none
Integrations             none

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

According to the docs, pages that start with an underscore should be automatically excluded from a site. However, when using v5 Content Layer API to define a collection, pages that start with an underscore are not excluded.

This issue does not happen with v4 nor does it happen when using v5 legacy content collections.

Steps to reproduce

  1. Open repro
  2. View site root page

Actual Result
image

What's the expected result?

Pages that start with an underscore should be automatically excluded from the site.

Astro v4

Repro

image

Astro v5 Legacy Collections

Repro

image

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-pdzrjo-jqkoqpvj

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 Dec 13, 2024
@techfg techfg changed the title Content Layer API based collections do not exclude pages starting with underscore (_) Content Layer based collections do not exclude pages starting with underscore (_) Dec 13, 2024
@ArmandPhilippot
Copy link
Member

The "Excluded Pages" section in the documentation applies to files in the src/pages folder. This behavior is unchanged.

But, yes, there is a difference between v4 and v5: files starting with an underscore in your content collections are no longer automatically excluded because the Content Layer API can retrieve data from many more sources. So it is not safe to expect an underscore to mean exclude that file.

If you need to exclude those files, you can do that in src/content.config.ts by updating your pattern:

-loader: glob({ base: './src/content/docs', pattern: '**/*.{md,mdx}' }),
+loader: glob({ base: './src/content/docs', pattern: '**/[^_]*.{md,mdx}' }),

You can see this pattern in the v5 upgrade guide

@ascorbic
Copy link
Contributor

Yes, @ArmandPhilippot is correct: this is as designed. If you want to exclude underscores then you can put that in the glob. The goal with the glob loader is to give you the flexibility to decide what you want to include or exclude.

@techfg
Copy link
Author

techfg commented Dec 13, 2024

Thanks for the clarification and makes sense, appreciate @ArmandPhilippot championing doc updates to make the content collection v4 behavior change clearer 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage Issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

3 participants