createContentLoader #

Creates a data loader that lists the Markdown pages matching a pattern, with their URL and frontmatter.

Usage #

TypeScript
import { 
createContentLoader
} from 'kawapress'
export default
createContentLoader
('./posts/*.md', {
excerpt
: true,
transform
:
pages
=>
pages
.
slice
(0, 10),
})

Parameters

watchstring | string[]

Glob pattern, or a list of them, for the Markdown files. Relative patterns start from the loader file.

optionsoptionalContentLoaderOptions<T>

What to keep for each page, and how to reshape the result.

default {}

includeSrcoptionalboolean

Keep the Markdown source of each page in src.

renderoptionalboolean

Render each page to HTML and keep it in html.

excerptoptionalContentExcerpt

Keep an excerpt of each page in excerpt.

transformoptional(data: ContentData[]): MaybePromise<T>

Reshapes the result, for example to sort or filter pages.

globOptionsoptionalDataLoaderGlobOptions

Extra options for matching files.

Returns A loader to export from a .data.ts file.

Notes #

Use transform to sort or trim the list before it is sent to the browser.

Full type signature
TypeScript
function createContentLoader<T = ContentData[]>(
  watch: string | string[],
  options?: ContentLoaderOptions<T>,
): ContentLoader<T>

Edit this page

Comments