@contentmap/astro
v1.2.0
Published
Astro content-layer loader backed by contentmap.
Readme
@contentmap/astro
An Astro content-layer loader backed by contentmap.
Astro 5 ships its own content layer. This package plugs contentmap into it as a loader, so you keep Astro's getCollection() API while contentmap does the parsing, validation and transforms — which means the same config and the same typed output as every other framework you target.
Install
npm i @contentmap/astroUse
// src/content.config.ts
import { defineCollection } from 'astro:content'
import { contentmapLoader } from '@contentmap/astro'
export const collections = {
posts: defineCollection({
loader: contentmapLoader({ collection: 'posts' })
})
}---
import { getCollection } from 'astro:content'
const posts = await getCollection('posts')
---Astro's dev server reloads when content changes.
Why use this rather than Astro's own loaders
Astro's built-in glob() loader is good. Use this one when you want a single content definition shared across more than one framework, or when you want contentmap's transforms, cross-collection references and asset pipeline behind Astro's API.
Options
collection names the contentmap collection to expose. Every BuilderOptions field is also accepted.
Links
MIT
