-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename getEntry to getEntryBySlug (#5893)
* 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 <[email protected]> * 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 <[email protected]>
- Loading branch information
1 parent
4f64901
commit be901dc
Showing
6 changed files
with
61 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
--- | ||
'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: | ||
|
||
```astro | ||
--- | ||
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! --> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 5 additions & 5 deletions
10
packages/astro/test/fixtures/content-collections/src/pages/entries.json.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters