Source Interface
A source is an object that implements theSource interface:
Virtual Files
Virtual files represent your content in Fumadocs’ format:Creating a Basic Source
Here’s a simple example of creating a custom source:lib/custom-source.ts
Using the Source with Loader
Once you have a source, use it with the loader:lib/source.ts
Database Source Example
Here’s an example of creating a source from a database:lib/db-source.ts
lib/source.ts
CMS Source Example
Connect to a headless CMS like Contentful or Sanity:lib/cms-source.ts
Transforming Sources
Use theupdate helper to transform an existing source:
Advanced: Multiple Sources
Combine multiple sources using themultiple helper:
Custom Data Types
ExtendPageData and MetaData with your own fields:
Source API Reference
Base Interfaces
Helper Functions
Loader Integration
The loader provides utilities for working with your source:Type Safety
The Source API is fully typed:Remote Content Example
Fetch content from a remote API:lib/remote-source.ts
File System Source Example
Create a source from local files without using Fumadocs MDX:lib/fs-source.ts
Best Practices
- Type Safety: Always extend
PageDataandMetaDatafor type-safe custom fields - Virtual Paths: Use consistent virtual paths that match your URL structure
- Error Handling: Handle errors gracefully when fetching from external sources
- Caching: Cache expensive operations when creating sources
- Validation: Validate data from external sources before creating virtual files
- Hot Reload: For development, consider implementing file watching for local sources