File-based content management system for Nuxt.js applications with powerful querying and Vue component rendering in Markdown
npx @tessl/cli install tessl/npm-nuxt--content@3.6.0Nuxt Content is a comprehensive content management module for Nuxt.js applications that enables developers to build file-based content systems with powerful querying capabilities. It reads content from directories containing Markdown, YAML, CSV, or JSON files and creates a data layer with full TypeScript support, Vue component rendering in Markdown through MDC syntax, and blazing-fast hot module replacement during development.
npm install @nuxt/contentimport { queryCollection, queryCollectionNavigation } from '#content/composables';
import { ContentRenderer } from '#content/components';For direct module imports:
import { defineCollection, defineContentConfig, defineTransformer, z } from '@nuxt/content/utils';
import { findPageBreadcrumb, findPageChildren, findPageSiblings, findPageHeadline } from '@nuxt/content/utils';
import { field, group } from '@nuxt/content/preview';
import { compressTree, decompressTree, visit } from '@nuxt/content/runtime';// In pages/[...slug].vue or other composables
export default defineComponent({
async setup() {
// Query a single content item
const article = await queryCollection('articles')
.path('/blog/my-article')
.first();
// Query multiple items with filtering
const posts = await queryCollection('blog')
.where('published', '=', true)
.order('date', 'DESC')
.limit(10)
.all();
// Generate navigation from content
const nav = await queryCollectionNavigation('pages');
return { article, posts, nav };
}
})<template>
<!-- Render content with full MDC support -->
<ContentRenderer :value="article" />
</template>Nuxt Content is built around several key architectural components:
Powerful query system with fluent API for filtering, sorting, and retrieving content from collections. Includes full TypeScript support and SQLite-based performance.
function queryCollection<T>(collection: T): CollectionQueryBuilder<Collections[T]>;
interface CollectionQueryBuilder<T> {
path(path: string): CollectionQueryBuilder<T>;
select<K>(...fields: K[]): CollectionQueryBuilder<Pick<T, K>>;
where(field: string, operator: SQLOperator, value?: unknown): CollectionQueryBuilder<T>;
order(field: keyof T, direction: 'ASC' | 'DESC'): CollectionQueryBuilder<T>;
limit(limit: number): CollectionQueryBuilder<T>;
skip(skip: number): CollectionQueryBuilder<T>;
all(): Promise<T[]>;
first(): Promise<T | null>;
count(field?: keyof T | '*', distinct?: boolean): Promise<number>;
}Automatically generate navigation trees and hierarchical structures from your content collections with customizable field selection and filtering.
function queryCollectionNavigation<T>(
collection: T,
fields?: Array<keyof PageCollections[T]>
): ChainablePromise<T, ContentNavigationItem[]>;
interface ContentNavigationItem {
title: string;
path: string;
stem?: string;
children?: ContentNavigationItem[];
page?: false;
[key: string]: unknown;
}Vue component system for rendering content with MDC (Markdown Components) support, custom component mapping, and prose styling.
interface ContentRendererProps {
value: object;
excerpt?: boolean;
tag?: string;
components?: object;
data?: object;
prose?: boolean;
class?: string | object;
unwrap?: boolean | string;
}Type-safe collection definition system with schema validation, custom sources, and flexible content organization.
function defineCollection<T>(collection: Collection<T>): DefinedCollection;
function defineContentConfig(config: ContentConfig): ContentConfig;
interface Collection<T> {
type: 'page' | 'data';
source?: string | CustomCollectionSource;
schema?: ZodSchema<T>;
fields?: CollectionFields<T>;
}Comprehensive module configuration with database settings, preview mode, build options, and experimental features.
interface ModuleOptions {
database: DatabaseConfig;
preview: PreviewOptions;
watch: WatchOptions;
renderer: RendererOptions;
build: BuildOptions;
experimental: ExperimentalOptions;
}Live content editing system with field definitions, authentication, and real-time preview capabilities.
function field(config: FieldConfig): PreviewField;
function group(config: GroupConfig): PreviewGroup;
interface PreviewField {
type: PickerTypes;
name: string;
label?: string;
required?: boolean;
}Helper functions for working with navigation trees, extracting breadcrumbs, children, siblings, and headlines from hierarchical content structures.
function findPageBreadcrumb(
navigation?: ContentNavigationItem[],
path?: string | undefined | null,
options?: FindPageBreadcrumbOptions
): ContentNavigationItem[];
function findPageChildren(
navigation?: ContentNavigationItem[],
path?: string | undefined | null,
options?: FindPageOptions
): ContentNavigationItem[];
function findPageSiblings(
navigation?: ContentNavigationItem[],
path?: string | undefined | null,
options?: FindPageOptions
): ContentNavigationItem[];
function findPageHeadline(
navigation?: ContentNavigationItem[],
path?: string | undefined | null,
options?: FindPageOptions
): string | undefined;Low-level utilities for working with content trees, compression, and AST manipulation for advanced content processing scenarios.
function compressTree(input: MDCRoot): MinimarkTree;
function decompressTree(input: Tree): MDCRoot;
function visit(
tree: Tree,
checker: (node: Node) => boolean,
visitor: (node: Node) => Node | undefined
): void;type SQLOperator = '=' | '!=' | '>' | '<' | '>=' | '<=' | 'IN' | 'NOT IN' | 'LIKE' | 'NOT LIKE';
interface Collections {
[key: string]: CollectionType;
}
interface PageCollections {
[key: string]: PageCollectionType;
}
interface ChainablePromise<T, R> extends Promise<R> {
collection: T;
}
interface FindPageBreadcrumbOptions {
current?: boolean;
indexAsChild?: boolean;
}
interface FindPageOptions {
indexAsChild?: boolean;
}
interface MDCRoot {
type: 'root';
children: Node[];
}
interface MinimarkTree {
type: 'minimark';
value: unknown;
}
interface Tree {
type: string;
value?: unknown;
}
interface Node {
type: string;
[key: string]: unknown;
}