skip to content
Alvin Lucillo

Astro multiple collections

/ 1 min read

πŸ’» Tech

In Astro, you can create multiple collections by defining it in config.ts file that’s one level higher than the collection folders.

For example, suppose we have the following folder structure:

β”œβ”€β”€ content
β”‚   β”œβ”€β”€ blogs           <-- collection 1
β”‚   β”œβ”€β”€ projects        <-- collection 2
β”‚   └── config.ts       <-- define collections here

Inside config.ts, the collections are defined and exported. The name of the collection is already the key and the folder name where the markdown files are located.

const blogs = defineCollection({
	// ...
});
const projects = defineCollection({
	// ...
});

export const collections = { journal, tech };