index
Interfaces
Collection
The query surface of one collection.
Type Parameters
Name
Name extends string
Data
Data
Methods
getCollection()
getCollection(filter?): Promise<Entry<Data>[]>;Parameters
filter?
(entry) => unknown
Returns
Promise<Entry<Data>[]>
getEntry()
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
loader: Loader;schema
schema: S;ContentBuilder
The builder createContent hands to its callback.
Methods
collection()
collection<S>(input): CollectionDefinition<S>;Type Parameters
S
S extends StandardSchemaV1<unknown>
Parameters
input
loader
schema
S
Returns
reference()
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
name: string;Methods
load()
load(context): void | Promise<void>;Parameters
context
Returns
void | Promise<void>
watchedPaths()?
optional watchedPaths(): string[];Returns
string[]
Entry
One entry of a collection, as a caller sees it.
Type Parameters
Data
Data
Properties
collection
collection: string;data
data: Data;filePath?
optional filePath?: string;id
id: string;Methods
render()
render(): Promise<RenderedEntry>;Returns
Promise<RenderedEntry>
EntryBody
The raw source of an entry's document, before anything renders it.
Properties
format
format: "md" | "mdx";source
source: string;GenerateIdOptions
Options handed to a loaders.glob generateId function.
Properties
base
base: string;The directory the pattern resolved against.
data
data: Record<string, unknown>;The parsed data of the entry, for an id derived from frontmatter.
entry
entry: string;The matched path, relative to base.
Heading
A heading collected from a Markdown or MDX document.
Properties
depth
depth: number;slug
slug: string;text
text: string;LiveEntry
What a LiveLoader returns for one entry.
Type Parameters
Data
Data = Record<string, unknown>
Properties
body?
optional body?: EntryBody;data
data: Data;id
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
name: string;Methods
loadCollection()
loadCollection(): Promise<LiveEntry<Data>[]>;Returns
Promise<LiveEntry<Data>[]>
loadEntry()
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?
optional body?: EntryBody;data
data: unknown;filePath?
optional filePath?: string;id
id: string;LoaderContext
What a loader is handed to read its source and validate what it found.
Properties
collection
collection: string;root
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
store: object;set()
set(entry): void;Parameters
entry
Returns
void
Methods
parseData()
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
collection: C;id
id: string;RenderedEntry
What entry.render() resolves to.
Properties
Content
Content: (handle) => () => RemixNode;Parameters
handle
Handle<Record<string, unknown>>
Returns
() => RemixNode
headings
headings: Heading[];Type Aliases
CollectionEntry
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
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()
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>