Skip to content

Commit

Permalink
expand on getting started collections
Browse files Browse the repository at this point in the history
  • Loading branch information
souporserious committed Oct 5, 2024
1 parent 28c5f36 commit 5d8b646
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions apps/site/docs/02.getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,40 @@ Prepending the renoun CLI ensures that the renoun process starts before your fra

## Creating a Collection

The `collection` utility is a core concept in renoun. This allows you to render a collection of files from the file system:
The `collection` utility is a core concept in renoun. This allows you to query a collection of files from the file system. For example, to create a list of blog posts or documentation pages we can query all the MDX files in a directory:

```tsx
import { collection } from 'renoun/collections'

const posts = collection({ filePattern: 'posts/*.mdx' })
const posts = collection({
filePattern: 'posts/*.mdx',
})
```

We can then constrain the collection by providing types for the exports we're interested in querying:

```tsx
import { collection } from 'renoun/collections'
import type { MDXContent } from 'renoun/mdx'

const posts = collection<{
default: MDXContent
}>({
filePattern: 'posts/*.mdx',
})
```

Finally, we can use this collection to render the contents of our MDX files:

```tsx
import { collection } from 'renoun/collections'
import type { MDXContent } from 'renoun/mdx'

const posts = collection<{
default: MDXContent
}>({
filePattern: 'posts/*.mdx',
})

export default async function Page({ params }: { params: { slug: string } }) {
const Content = await posts
Expand All @@ -50,13 +78,13 @@ export default async function Page({ params }: { params: { slug: string } }) {
}
```

This will create a collection of all MDX files in the `posts` directory and render them based on the provided slug. Collections are not limited to MDX files and can be used with any file type.
This will create a collection of all MDX files in the `posts` directory and render them based on the provided slug. Collections are not limited to MDX files and can be used with _any file type_.

<Note>

When creating a new collection for the first time, a dynamic import will be
generated at the collection's call site for each targeted extension during the development or build
process. These imports are necessary to load the collection's targeted files from
process. These imports are necessary to load the targeted files from
the file system.

```ts
Expand Down

0 comments on commit 5d8b646

Please sign in to comment.