mirror of
https://github.com/withastro/astro.git
synced 2024-12-23 21:53:55 -05:00
be901dc98c
* Rename getEntry to getEntryBySchema * Improve entrySlug types and return undefined * Add changeset * Update packages/astro/src/content/template/types.d.ts Co-authored-by: Ben Holmes <hey@bholmes.dev> * Update the types to accept both raw string and known value * Add comment on the implementation not currently being O(1) Co-authored-by: Ben Holmes <hey@bholmes.dev>
627 B
627 B
astro |
---|
major |
Move getEntry to getEntryBySlug
This change moves getEntry
to getEntryBySlug
and accepts a slug rather than an id.
In order to improve support in [id].astro
routes, particularly in SSR where you do not know what the id of a collection is. Using getEntryBySlug
instead allows you to map the [id]
param in your route to the entry. You can use it like this:
---
import { getEntryBySlug } from 'astro:content';
const entry = await getEntryBySlug('docs', Astro.params.id);
if(!entry) {
return new Response(null, {
status: 404
});
}
---
<!-- You have an entry! Use it! -->