Skip to content
Pitlane

index

Interfaces

Collection

The query surface of one collection.

Type Parameters

Name

Name extends string

Data

Data

Methods

getCollection()
ts
getCollection(filter?): Promise<Entry<Data>[]>;
Parameters
filter?

(entry) => unknown

Returns

Promise<Entry<Data>[]>

getEntry()
ts
getEntry(id): Promise<Entry<Data> | undefined>;
Parameters
id

string | Reference<Name>

Returns

Promise<Entry<Data> | undefined>


CollectionDefinition

What c.collection({ loader, schema }) returns.

Type Parameters

S

S extends StandardSchemaV1 = StandardSchemaV1

Properties

loader
ts
loader: Loader;
schema
ts
schema: S;

ContentBuilder

The builder createContent hands to its callback.

Methods

collection()
ts
collection<S>(input): CollectionDefinition<S>;
Type Parameters
S

S extends StandardSchemaV1<unknown>

Parameters
input
loader

Loader

schema

S

Returns

CollectionDefinition<S>

reference()
ts
reference<C>(collection): ReferenceSchema<C>;
Type Parameters
C

C extends string

Parameters
collection

C

Returns

ReferenceSchema<C>


ContentLoader

A loader that resolves a whole collection by filling a store.

Its shape is the claim that one execution produces the complete answer, which is what lets contentLayer() run it during the build and inline the result.

Properties

name
ts
name: string;

Methods

load()
ts
load(context): void | Promise<void>;
Parameters
context

LoaderContext

Returns

void | Promise<void>

watchedPaths()?
ts
optional watchedPaths(): string[];
Returns

string[]


Entry

One entry of a collection, as a caller sees it.

Type Parameters

Data

Data

Properties

collection
ts
collection: string;
data
ts
data: Data;
filePath?
ts
optional filePath?: string;
id
ts
id: string;

Methods

render()
ts
render(): Promise<RenderedEntry>;
Returns

Promise<RenderedEntry>


EntryBody

The raw source of an entry's document, before anything renders it.

Properties

format
ts
format: "md" | "mdx";
source
ts
source: string;

GenerateIdOptions

Options handed to a loaders.glob generateId function.

Properties

base
ts
base: string;

The directory the pattern resolved against.

data
ts
data: Record<string, unknown>;

The parsed data of the entry, for an id derived from frontmatter.

entry
ts
entry: string;

The matched path, relative to base.


Heading

A heading collected from a Markdown or MDX document.

Properties

depth
ts
depth: number;
slug
ts
slug: string;
text
ts
text: string;

LiveEntry

What a LiveLoader returns for one entry.

Type Parameters

Data

Data = Record<string, unknown>

Properties

body?
ts
optional body?: EntryBody;
data
ts
data: Data;
id
ts
id: string;

LiveLoader

A loader that answers one query at a time.

There is no store to fill and so nothing to serialize: the only way to get entries out of it is to ask, which means asking on every read.

Type Parameters

Data

Data = Record<string, unknown>

Properties

name
ts
name: string;

Methods

loadCollection()
ts
loadCollection(): Promise<LiveEntry<Data>[]>;
Returns

Promise<LiveEntry<Data>[]>

loadEntry()
ts
loadEntry(id): Promise<LiveEntry<Data> | undefined>;
Parameters
id

string

Returns

Promise<LiveEntry<Data> | undefined>


LoadedEntry

What a ContentLoader writes into the store for one entry.

Properties

body?
ts
optional body?: EntryBody;
data
ts
data: unknown;
filePath?
ts
optional filePath?: string;
id
ts
id: string;

LoaderContext

What a loader is handed to read its source and validate what it found.

Properties

collection
ts
collection: string;
root
ts
root: string;

The project root a relative path resolves against.

process.cwd() at runtime, and the Vite root under contentLayer(), which is what keeps a collection pointing at the same files when the build runs from somewhere else.

store
ts
store: object;
set()
ts
set(entry): void;
Parameters
entry

LoadedEntry

Returns

void

Methods

parseData()
ts
parseData<D>(input): Promise<D>;
Type Parameters
D

D

Parameters
input
data

unknown

filePath?

string

id

string

Returns

Promise<D>


Reference

A resolved pointer from one entry to another, produced by c.reference(collection).

The collection type parameter is what stops a Reference<"blog"> reaching content.authors.getEntry.

Type Parameters

C

C extends string

Properties

collection
ts
collection: C;
id
ts
id: string;

RenderedEntry

What entry.render() resolves to.

Properties

Content
ts
Content: (handle) => () => RemixNode;
Parameters
handle

Handle<Record<string, unknown>>

Returns

() => RemixNode

headings
ts
headings: Heading[];

Type Aliases

CollectionEntry

ts
type CollectionEntry<C> = C extends Collection<string, infer Data> ? Entry<Data> : never;

One entry of collection, named the way an application thinks of it: CollectionEntry<typeof content.blog>.

Entry is keyed by the shape of the data, which is what the query methods resolve to and all this package needs internally. An application has the collection rather than the shape, and pulling one out of the other is a conditional type every consumer would otherwise write for itself.

Type Parameters

C

C


Loader

ts
type Loader = 
  | ContentLoader
| LiveLoader<unknown>;

Either kind of loader.

A LiveLoader's own Data parameter is for whoever writes it; a collection accepts any of them, because what a loader hands back is unvalidated until parseData has seen it.

Functions

createContent()

ts
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) => T

Returns

Content<T>