Skip to content

Search the guides, deployment pages, and API reference.

createContent

import { createContent } from "@pitlane/content";
function createContent<T>(build): Content<T>;

Declares a set of content collections.

Returns the collection object synchronously without loading entries. Reads and rendering remain asynchronous. Declaration errors throw here.

Under contentLayer(), registers deferred population work. The plugin awaits it after evaluating the declarations and before emitting the bundle.

Type Parameters

T

T extends Record<string, CollectionDefinition<StandardSchemaV1<unknown>>>

Parameters

build

(c: ContentBuilder) => T

Receives the ContentBuilder and returns one collection per key, each declared with c.collection({ loader, schema })

Returns

Content<T>

One Collection per key of the object build returned

Throws

Error when c.reference() names a collection build did not declare

See

Example

app/content.ts
import { createContent } from "@pitlane/content";
import * as loaders from "@pitlane/content/loaders";
import * as s from "remix/data-schema";
import * as coerce from "remix/data-schema/coerce";
export let content = createContent(c => ({
blog: c.collection({
loader: loaders.glob({ base: "app/content/blog", pattern: "*.{md,mdx}" }),
schema: s.object({
title: s.string(),
pubDate: coerce.date(),
author: c.reference("authors"),
}),
}),
authors: c.collection({
loader: loaders.file("app/content/authors.json"),
schema: s.object({ name: s.string() }),
}),
}));
let posts = await content.blog.getCollection();
let post = await content.blog.getEntry("hello-world");