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
| Option | Type | Notes |
|---|---|---|
contentDir | string | Required. Directory containing source .md / .mdx files. |
baseUrl | string | Used for absolute URLs in TOC and search index. |
groups | DocsGroup[] | Doc groups for navigation. Empty groups = all pages ungrouped. |
mounts | DocsPathMount[] | Multi-mount routing (advanced). |
remarkPlugins | PluggableList | Defaults to Leadtype's source preset. Pass [] to skip transforms. |
typeTableBasePath | string | Base directory for <ExtractedTypeTable> / <AutoTypeTable path="…">. Defaults to the parent of contentDir. |
typeTableStrict | boolean | Throw when a referenced type cannot be extracted instead of emitting a visible warning. |
toc | DocsTableOfContentsOptions | false | TOC tuning; false skips TOC entirely. |
searchIndex | CreateDocsSearchIndexOptions | Search-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-remoteinstead 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
Astro Content Collections
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
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)
Nuxt
SvelteKit + mdsvex
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:
- Add
createMdxSourcePlugins()to the remark list so<include>/<ExtractedTypeTable>resolve at build time. - Implement components against the tag types from
leadtype/mdx— intersect with your framework's child type. - 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.