content.get()
Read one document by its public path, parsing and caching the body on demand.
content.get(path, options?)
Reads one document by its public path, parsing the body (and caching it) on demand.
Parameters:
path: public path of the document (e.g./posts/hello).options?: optional, see Options. Passfresh: trueto bypass the cache and re-parse from the source.
Returns: Promise<ContentFile | null | undefined>, where null means no entry maps to the path and undefined means the entry exists but is not a document (e.g. a media file).
usage.ts
const page = await content.get('/posts/hello')
if (!page) return notFound()
page.data // frontmatter (typed)
page.nodes // the parsed MarkdownDocument nodes
page.meta // { kind, type, key, source, extension, stem, partial }With generated types, a known path auto-narrows the return type; otherwise pass a type parameter: content.get<PostFrontmatter>('/posts/hello').
Options
| Option | Type | Default | Description |
|---|---|---|---|
fresh | boolean | false | Bypass the cache and re-parse the body from the source. |
fresh
By default get() serves the cached parsed body when one is available. Pass fresh: true to skip the cache and re-read and re-parse the document straight from its source, refreshing the cached entry in the process.
Usage
usage.ts
const page = await content.get('/posts/hello')