Content
Collections & Pagination
1 min read
Collections group content nodes into named sets with optional pagination.
Define a collection
export default defineConfig({
collections: [
{
name: "posts",
types: ["post"], // content type names to include
paginate: { perPage: 10 }, // optional pagination
outputPattern: "/blog/page/:n/", // optional URL pattern
},
],
});
Output URLs
With outputPattern: "/blog/page/:n/":
- Page 1 →
/blog/(no/page/1/redirect needed) - Page 2 →
/blog/page/2/ - Page 3 →
/blog/page/3/
Without outputPattern, the collection name is used: /:name/ and /:name/page/:n/.
Sorting
Sorting is inherited from the content type's sortBy and sortOrder fields.
For a collection spanning multiple types, the first type's sort settings are used.
Tag pages
Tag listing pages are generated automatically from the tags front matter field:
/tags/javascript/— all content taggedjavascript- Paginated if there are more than the default per-page count
Accessing collections in templates
// In a React template
const posts = context.allContent.collections.get("posts") ?? [];
// Or directly from byType
const allPosts = context.allContent.byType.get("post") ?? [];