Quickstart CLI
- 
Install required packages:
We have to install the following packages:
@content-collections/core@content-collections/cliconcurrently
pnpm add --save-dev @content-collections/core @content-collections/cli concurrently - 
Adjust your
tsconfig.json:{ "compilerOptions": { // ... "paths": { "content-collections": ["./.content-collections/generated"] } } }We require a path alias for the generated files. This is necessary because the CLI will generate the files in the
.content-collections/generatedfolder. - 
Add the content-collection cli to your
package.jsonscripts:{ "scripts": { "dev": "concurrently \"content-collections watch\" \"build-scripts dev\"", "build": "content-collections build && build-scripts build" } }First, we modify the
devscript to simultaneously execute thecontent-collections watchcommand along with our regulardevcommand.Next, we execute the
content-collections buildcommand prior to our regularbuildcommand.Note: Make sure to replace
build-scriptswith the appropriate command for your framework, such asnextorvite. - 
Create a
content-collections.tsfile at the root of your project:import { defineCollection, defineConfig } from "@content-collections/core"; const posts = defineCollection({ name: "posts", directory: "src/posts", include: "**/*.md", schema: (z) => ({ title: z.string(), summary: z.string(), }), }); export default defineConfig({ collections: [posts], });This file defines a collection named
postsin thesrc/postsfolder. The collection will include all markdown files (**/*.md) and the schema will validate thetitleandsummaryfields.For more information about the configuration have a look at the documentation.
 - 
Create your content files (e.g.:
src/posts/hello-world.md):--- title: "Hello world" summary: "This is my first post!" --- # Hello world This is my first post! ... rest of the contentYou can create unlimited content files. These files will be validated against the schema defined in the
content-collections.tsfile. If the files are valid, they will be automatically added to thepostscollection. - 
Usage in your code:
import { allPosts } from "content-collections";Now you can just import the
allPostscollection and use it in your code. TheallPostscollection will contain all posts that are valid. Thepostobject will contain thetitle,summaryandcontentfields as well as some meta information in the_metafield.