Reference

createDocsSource

createDocsSource()

createDocsSource() is the framework-neutral entry point for any consumer that wants to render leadtype-authored MDX in their own renderer. It composes leadtype's primitives (resolveDocsNavigation, convertMdxFile, createDocsSearchIndex, resolveInclude) into a single source object.

For fumadocs specifically, use the thin leadtype/fumadocs adapter that wraps this primitive.

Configuration

OptionTypeNotes
contentDirstringRequired. Directory containing source .md / .mdx files.
baseUrlstringUsed for absolute URLs in TOC and search index.
groupsDocsGroup[]Doc groups for navigation. Empty groups = all pages ungrouped.
mountsDocsPathMount[]Multi-mount routing (advanced).
remarkPluginsPluggableListDefaults to Leadtype's source preset. Pass [] to skip transforms.
typeTableBasePathstringBase directory for <ExtractedTypeTable> / <AutoTypeTable path="…">. Defaults to the parent of contentDir.
typeTableStrictbooleanThrow when a referenced type cannot be extracted instead of emitting a visible warning.
tocDocsTableOfContentsOptions | falseTOC tuning; false skips TOC entirely.
searchIndexCreateDocsSearchIndexOptionsSearch-index tuning.

createDocsSource does no I/O on construction beyond a directory scan for listPages() caching. Page bodies are loaded lazily.

Source methods

getNavigation(): Promise<DocsNavigation>

Computes navigation from the configured groups + filesystem state. Identical shape to resolveDocsNavigation from leadtype/llm.

listPages(): Promise<DocsPageMeta[]>

Enumerates every doc page under contentDir. Each entry includes:

Result is cached; subsequent calls don't re-walk the disk.

loadPage(slug): Promise<DocsPage | null>

Loads a single page. Returns null if no slug matches. Accepts either an array or a slash-joined string.

Returned object extends DocsPageMeta with:

buildSearchIndex(): Promise<DocsSearchBundle>

Resolves every page through convertMdxFile and builds a DocsSearchIndex. Document IDs match each page's urlPath.

resolveInclude(specifier, options?): Promise<IncludeResolution>

Convenience wrapper around resolveInclude from leadtype/mdx with fromDir defaulted to contentDir. Useful for loading partials outside of the MDX compile path.

Choosing between loadPage and direct .mdx imports

For most bundler-driven consumers (Next App Router, Vite, Astro), you'll import source .mdx directly and let the bundler's MDX pipeline compile it with createMdxSourcePlugins(). loadPage() is for cases where you need the resolved markdown body or AST programmatically:

  • Server-rendering through next-mdx-remote instead of bundler-native MDX
  • Streaming partials to an agent / LLM at runtime
  • Building a custom TOC or analyzing document structure

Framework integrations

createDocsSource() is framework-neutral. Wire it into whatever you're already using:

Next App Router

next.config.mjs
app/docs/[[...slug]]/page.tsx

Astro Content Collections

astro.config.mjs

Use Astro's built-in content collection schema for typed frontmatter; use createDocsSource() only when you need leadtype's navigation, search index, or programmatic include resolution.

TanStack Start

vite.config.ts

Pair with a TanStack Router catch-all (src/routes/docs/$.tsx) that consumes a build-time manifest generated from createDocsSource().listPages(). See Use the source primitive → TanStack Start for the catch-all snippet.

Vite + @mdx-js/rollup (works for Vue, Solid, Svelte starters)

vite.config.ts

Nuxt

nuxt.config.ts

SvelteKit + mdsvex

svelte.config.js

Fumadocs

See the dedicated Integrate with Fumadocs page — leadtype ships a first-party leadtype/fumadocs adapter.

Pattern for any other framework

If your framework's MDX integration accepts a remark plugin list, leadtype works. Three pieces:

  1. Add createMdxSourcePlugins() to the remark list so <include> / <ExtractedTypeTable> resolve at build time.
  2. Implement components against the tag types from leadtype/mdx — intersect with your framework's child type.
  3. Optionally call createDocsSource() for navigation, search, and programmatic page loading.

No leadtype code runs in your client bundle unless you explicitly import a runtime helper. The source primitive is server-side / build-time.