@flexacms/astro
v0.3.1
Published
Astro content loader for the Flexa headless CMS.
Maintainers
Readme
@flexacms/astro
Load Flexa content into Astro content collections (Astro 5+ content layer).
npm install @flexacms/astro// src/content.config.ts
import { defineCollection } from 'astro:content';
import { flexaLoader } from '@flexacms/astro';
const posts = defineCollection({
loader: flexaLoader({
entity: 'posts',
apiKey: import.meta.env.FLEXA_API_KEY,
// url: import.meta.env.FLEXA_URL, // optional, defaults to https://flexacms.com
}),
});
export const collections = { posts };---
import { getCollection } from 'astro:content';
const posts = await getCollection('posts');
---
{posts.map((post) => <a href={`/blog/${post.id}`}>{post.data.title}</a>)}Each entry is stored with its slug as id (or its numeric id when it has no slug) and the full API entry as data. By default only published entries are loaded.
| Option | Default | |
| ---------------- | ----------------------------- | ------------------------------------------------------------- |
| entity | — | Entity slug |
| query | { status: 'published' } | status, search, category, perPage, includeRelations |
| id | slug, then id | (entry) => string |
| url | FLEXA_URL, then https://flexacms.com | |
| apiKey | FLEXA_API_KEY | |
Add a schema to defineCollection to validate or reshape data with Zod.
