withastro/astro

Duplicate slugs does not throw error

Closed this issue · 4 comments

Astro Info

Astro                    v5.0.0-beta.12
Node                     v18.20.3
System                   Linux (x64)
Package Manager          npm
Output                   static
Adapter                  none
Integrations             @astrojs/preact

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

No response

Describe the Bug

Using the Astro tutorial on the content collections branch.

If I set the slug in the frontmatter of post-1.md and post-2.md to identical values (post-A in the MRE), the second post disappears from the /blog index page.

What's the expected result?

Loud error from Astro complaining about identical slugs.

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-bew6ny4w?file=src%2Fblog%2Fpost-2.md

Participation

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

@mvsoom, the slug isn't part of the new content layer. The unique identifier of each entry is now id, so you need to define slug in your schema.

OK, thank you. But as slug is a magic way to way to override id, and the latter must be unique, isn't it better to validate this automatically?

No, slug isn't a way to override id. Maybe it was true for the old content collections, but it was a mistake in our design. In the content layer, there's just one unique field, which is id.

If you need slug in your collection via content layer, you must define it and do the validation yourself.