Skip to content

Allow for empty content collections #8336

@pReya

Description

@pReya

Astro Info

Astro version            v2.9.6
Package manager          npm
Platform                 darwin
Architecture             arm64
Adapter                  Couldn't determine.
Integrations             @astrojs/react, @astrojs/tailwind, auto-import, @astrojs/mdx

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

No response

Describe the Bug

I'm well aware some might see this as a new feature, but I have to disagree. Content collections should be able to handle a "empty state" – meaning you should be able to use a content collection which has no items. Currently, this will always throw an error, so the page basically breaks. But there are plenty valid use cases for empty collections and it should be possible to still use the site (e.g. throw a warning instead of an error).

Also the error is technically not correct. This is what it says:

 error   The collection examples does not exist. Ensure a collection directory with this name exists.

Yet, this is also the error, when the folder exists, but there's just no file in it.

Am I missing something or is this really an oversight in the concept of content collections?

What's the expected result?

Page should still render

Link to Minimal Reproducible Example

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

Participation

  • I am willing to submit a pull request for this issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    - P3: minor bugAn edge case that only affects very specific usage (priority)feat: content collectionsRelated to the Content Collections feature (scope)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions