0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-23 21:53:55 -05:00

[ci] yarn format

This commit is contained in:
FredKSchott 2021-06-15 00:22:00 +00:00 committed by GitHub Actions
parent 8399a4893e
commit 2ea15f4192

View file

@ -12,20 +12,23 @@ Astro Collections help you break up a larger set of data into multiple pages. Ex
**When to use Collections: When you need to reuse a single template to generate multiple pages from a larger dataset.** If you just want to generate a single page (ex: a long list of every post on your site) then you can just fetch that data on a normal Astro page without using the Collection API.
## Collections API
To create a new Astro Collection, you must do three things:
1. Create a new file in the `src/pages` directory that starts with the `$` symbol. This is required to enable the Collections API.
- Example: `src/pages/$posts.astro` -> `/posts/1`, `/posts/2`, etc.
- Example: `src/pages/$tags.astro` -> `/tags/:tag` (or `/tags/:tag/1`)
2. Define and export the `collection` prop: `collection.data` is how you'll access the data for every page in the collection. Astro populates this prop for you automatically. It MUST be named `collection` and it must be exported.
- Example: `export let collection;`
3. Define and export `createCollection` function: this tells Astro how to load and structure your collection data. Check out the examples below for documentation on how it should be implemented. It MUST be named `createCollection` and it must be exported.
- Example: `export async function createCollection() { /* ... */ }`
- API Reference: [createCollection][collection-api]
- Example: `src/pages/$posts.astro` -> `/posts/1`, `/posts/2`, etc.
- Example: `src/pages/$tags.astro` -> `/tags/:tag` (or `/tags/:tag/1`)
2. Define and export the `collection` prop: `collection.data` is how you'll access the data for every page in the collection. Astro populates this prop for you automatically. It MUST be named `collection` and it must be exported.
- Example: `export let collection;`
3. Define and export `createCollection` function: this tells Astro how to load and structure your collection data. Check out the examples below for documentation on how it should be implemented. It MUST be named `createCollection` and it must be exported.
- Example: `export async function createCollection() { /* ... */ }`
- API Reference: [createCollection][collection-api]
## Example: Simple Pagination