From 6a1fe4ed708d8492beef8d3aa2d055535b8e8b94 Mon Sep 17 00:00:00 2001 From: fuma-nama Date: Wed, 4 Sep 2024 13:41:23 +0800 Subject: [PATCH] Docs: Clarify root directory --- .../docs/content/docs/headless/source-api.mdx | 45 ++++++++++--------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/apps/docs/content/docs/headless/source-api.mdx b/apps/docs/content/docs/headless/source-api.mdx index 3a8b69948..4b293e96d 100644 --- a/apps/docs/content/docs/headless/source-api.mdx +++ b/apps/docs/content/docs/headless/source-api.mdx @@ -5,11 +5,11 @@ description: Turn a content source into a unified interface ## Usage -Source API is a helper to load file-system based content sources, it offers an unified interface to integrate different content sources with Fumadocs. +Source API is a helper to load file-system based content sources, it offers a unified interface to integrate content sources with Fumadocs. It handles some important jobs: -- Build page trees from file-system information +- Build page trees based on file system - Generate Urls and slugs based on file path - Output useful utilities to search or walk over files @@ -18,33 +18,16 @@ It doesn't rely on the real file system (zero `node:fs` usage), a virtual storag You can use it with built-in content sources like Fumadocs MDX. ```ts -import { map } from '@/.map'; import { createMDXSource } from 'fumadocs-mdx'; import { loader } from 'fumadocs-core/source'; export const docs = loader({ - source: createMDXSource(map), + source: createMDXSource(docs, meta), }); ``` > The output page tree strictly follows [Page Conventions](/docs/headless/page-conventions). -### Root Directory - -All files outside of the root directory will be ignored. - -```ts -import { loader } from 'fumadocs-core/source'; - -loader({ - rootDir: 'docs', -}); -``` - - - Relative paths, like `./` and `../` are not supported. - - ### Base URL As the `loader` function also generate an URL for each page, you can override the default base URL. @@ -78,6 +61,28 @@ export const utils = loader({ }); ``` +### Root Directory + +Filter the input files by its located directory. + +```ts +import { loader } from 'fumadocs-core/source'; + +loader({ + rootDir: 'test', +}); +``` + +Content sources only provide **a virtual file path** to the loader (like `test/index.mdx`). +Relative paths such as `./` and `../` are not supported. + + + +This is not equivalent to your content directory configured on content source (e.g. [Fumadocs MDX `dir` option](/docs/mdx/configuration#collections)). +Please use relevant options on your source instead. + + + ## Deep Dive As mentioned, Source API doesn't rely on real file systems.