Content Management
Velocity uses Astro’s Content Layer API for type-safe content management.
Content Collections
Section titled “Content Collections”Collections are defined in src/content.config.ts:
- blog — Blog posts in MDX format
- pages — Static pages
- authors — Author profiles (JSON)
- faqs — FAQ entries (JSON)
Directory Structure
Section titled “Directory Structure”src/content/├── blog/│ ├── en/│ │ ├── first-post.mdx│ │ └── second-post.md│ ├── es/│ │ └── primer-post.mdx│ └── fr/│ └── premier-post.mdx├── pages/├── authors/│ └── authors.json└── faqs/ └── faqs.jsonQuerying Content
Section titled “Querying Content”---import { getCollection } from 'astro:content';
// Get all published postsconst posts = await getCollection('blog', ({ data }) => { return import.meta.env.PROD ? data.draft !== true : true;});
// Filter by localeconst enPosts = posts.filter(post => post.data.locale === 'en');
// Sort by dateconst sortedPosts = posts.sort( (a, b) => b.data.publishedAt.valueOf() - a.data.publishedAt.valueOf());
// Get featured postsconst featured = posts.filter(post => post.data.featured);---Rendering Content
Section titled “Rendering Content”---import { getCollection, render } from 'astro:content';import BlogLayout from '@/layouts/BlogLayout.astro';
export async function getStaticPaths() { const posts = await getCollection('blog'); return posts.map((post) => ({ params: { slug: post.id }, props: { post }, }));}
const { post } = Astro.props;const { Content } = await render(post);---
<BlogLayout {...post.data}> <Content /></BlogLayout>Next Steps
Section titled “Next Steps”- Blog Posts — Creating blog content
- Other Collections — Authors, FAQs, pages