import { R as Root, I as Item, F as Folder, S as Separator } from './definitions-pJ7PybYY.js'; import { I18nConfig } from './i18n/index.js'; import { ReactNode } from 'react'; interface Source { files: VirtualFile[]; } interface SourceConfig { pageData: PageData; metaData: MetaData; } interface MetaData { icon?: string | undefined; title?: string | undefined; root?: boolean | undefined; pages?: string[] | undefined; defaultOpen?: boolean | undefined; collapsible?: boolean | undefined; description?: string | undefined; } interface PageData { icon?: string | undefined; title?: string; description?: string | undefined; } type VirtualFile = VirtualPage | VirtualMeta; interface BaseVirtualFile { /** * Virtualized path (relative to content directory) * * @example `docs/page.mdx` */ path: string; /** * Absolute path of the file */ absolutePath?: string; } interface VirtualPage extends BaseVirtualFile { type: 'page'; /** * Specified Slugs for page */ slugs?: string[]; data: Data; } interface VirtualMeta extends BaseVirtualFile { type: 'meta'; data: Data; } type _ConfigUnion_> = { [K in keyof T]: T[K] extends Source ? { pageData: Config['pageData'] & { type: K; }; metaData: Config['metaData'] & { type: K; }; } : never; }[keyof T]; declare function multiple>(sources: T): Source<_ConfigUnion_>; declare function source(config: { pages: VirtualPage[]; metas: VirtualMeta[]; }): Source<{ pageData: Page; metaData: Meta; }>; /** * update a source object in-place. */ declare function update(source: Source): { files(fn: (files: VirtualFile[]) => (VirtualPage | VirtualMeta)[]): typeof update<{ pageData: Page; metaData: Meta; }>; page(fn: (page: VirtualPage) => VirtualPage): typeof update<{ pageData: V; metaData: Config["metaData"]; }>; meta(fn: (meta: VirtualMeta) => VirtualMeta): typeof update<{ pageData: Config["pageData"]; metaData: V; }>; build(): Source; }; /** * In memory file system. */ declare class FileSystem { files: Map; folders: Map; constructor(inherit?: FileSystem); read(path: string): File | undefined; /** * get the direct children of folder (in virtual file path) */ readDir(path: string): string[] | undefined; write(path: string, file: File): void; /** * Delete files at specified path. * * @param path - the target path. * @param [recursive=false] - if set to `true`, it will also delete directories. */ delete(path: string, recursive?: boolean): boolean; getFiles(): string[]; makeDir(path: string): void; } type ContentStorage = FileSystem>; type ContentStorageFile = { path: string; absolutePath?: string; format: 'meta'; data: Config['metaData']; } | { path: string; absolutePath?: string; format: 'page'; slugs: string[]; data: Config['pageData']; }; /** * @param defaultLanguage - language to use when i18n is not configured. * @returns a map of locale and its content storage. * * in the storage, locale codes are removed from file paths, hence the same file will have same file paths in every storage. */ declare function buildContentStorage(loaderConfig: ResolvedLoaderConfig, defaultLanguage: string): Record; interface PageTreeBuilderContext { rootId: string; generateNodeId: () => string; options: PageTreeOptions; transformers: PageTreeTransformer[]; builder: PageTreeBuilder; storage: ContentStorage; getUrl: ResolvedLoaderConfig['url']; storages?: Record>; locale?: string; } interface PageTreeTransformer { file?: (this: PageTreeBuilderContext, node: Item, filePath?: string) => Item; folder?: (this: PageTreeBuilderContext, node: Folder, folderPath: string, metaPath?: string) => Folder; separator?: (this: PageTreeBuilderContext, node: Separator) => Separator; root?: (this: PageTreeBuilderContext, node: Root) => Root; } interface PageTreeOptions { id?: string; /** * Remove references to the file path of original nodes (`$ref`) * * @defaultValue false */ noRef?: boolean; /** * generate fallback page tree * * @defaultValue true */ generateFallback?: boolean; /** * Additional page tree transformers to apply */ transformers?: PageTreeTransformer[]; } interface PageTreeBuilder { build: (storage: ContentStorage, options?: PageTreeOptions) => Root; buildI18n: (storages: Record, options?: PageTreeOptions) => Record; } declare function createPageTreeBuilder(loaderConfig: ResolvedLoaderConfig): PageTreeBuilder; interface LoaderPlugin { name?: string; /** * Change the order of plugin: * - `pre`: before normal plugins * - `post`: after normal plugins */ enforce?: 'pre' | 'post'; /** * receive & replace loader options */ config?: (config: ResolvedLoaderConfig) => ResolvedLoaderConfig | void | undefined; /** * transform the storage after loading */ transformStorage?: (context: { storage: ContentStorage; }) => void; /** * transform the generated page tree */ transformPageTree?: PageTreeTransformer; } type LoaderPluginOption = LoaderPlugin | LoaderPluginOption[] | undefined; declare function buildPlugins(plugins: LoaderPluginOption[], sort?: boolean): LoaderPlugin[]; type IconResolver = (icon: string | undefined) => ReactNode; interface LoaderConfig { source: SourceConfig; i18n: I18nConfig | undefined; } interface LoaderOptions { baseUrl: string; i18n?: C['i18n']; url?: (slugs: string[], locale?: string) => string; /** * Additional options for page tree builder */ pageTree?: PageTreeOptions; plugins?: LoaderPluginOption[] | ((context: { typedPlugin: (plugin: LoaderPlugin) => LoaderPlugin; }) => LoaderPluginOption[]); icon?: IconResolver; slugs?: (info: { path: string; }) => string[]; } interface ResolvedLoaderConfig { source: Source; url: (slugs: string[], locale?: string) => string; plugins?: LoaderPlugin[]; pageTree?: PageTreeOptions; i18n?: I18nConfig | undefined; } interface SharedFileInfo { /** * Virtualized file path (relative to content directory) * * @example `docs/page.mdx` */ path: string; /** * Absolute path of the file */ absolutePath?: string; } interface Page extends SharedFileInfo { slugs: string[]; url: string; data: Data; locale?: string | undefined; } interface Meta extends SharedFileInfo { data: Data; } interface LoaderOutput { pageTree: Config['i18n'] extends I18nConfig ? Record : Root; getPageTree: (locale?: string) => Root; /** * get referenced page from href, supported: * * - relative file paths, like `./my/page.mdx`. * - generated page pathname, like `/docs/my/page`. */ getPageByHref: (href: string, options?: { language?: string; /** * resolve relative file paths in `href` from specified dirname, must be a virtual path. */ dir?: string; }) => { page: Page; hash?: string; } | undefined; /** * resolve special hrefs in a page, including: * * - relative file paths, like `./my/page.mdx`. */ resolveHref: (href: string, parent: Page) => string; /** * @internal */ _i18n?: I18nConfig; /** * Get a list of pages from specified language * * @param language - If empty, list pages from all languages. */ getPages: (language?: string) => Page[]; /** * get each language and its pages, empty if i18n is not enabled. */ getLanguages: () => { language: string; pages: Page[]; }[]; /** * Get page with slugs, the slugs can also be URI encoded. * * @param language - If empty, the default language will be used */ getPage: (slugs: string[] | undefined, language?: string) => Page | undefined; getNodePage: (node: Item, language?: string) => Page | undefined; getNodeMeta: (node: Folder, language?: string) => Meta | undefined; /** * generate static params for Next.js SSG * * @param slug - customise parameter name for slugs * @param lang - customise parameter name for lang */ generateParams: (slug?: TSlug, lang?: TLang) => (Record & Record)[]; /** * serialize page tree for non-RSC environments */ serializePageTree: (tree: Root) => Promise; } declare function createGetUrl(baseUrl: string, i18n?: I18nConfig): ResolvedLoaderConfig['url']; declare function loader(source: Source, options: LoaderOptions<{ source: NoInfer; i18n: I18n; }>): LoaderOutput<{ source: Config; i18n: I18n; }>; declare function loader(options: LoaderOptions<{ source: NoInfer; i18n: I18n; }> & { source: Source; }): LoaderOutput<{ source: Config; i18n: I18n; }>; type InferPageType> = Utils extends LoaderOutput ? Page : never; type InferMetaType> = Utils extends LoaderOutput ? Meta : never; export { type ContentStorage as C, FileSystem as F, type InferPageType as I, type LoaderPlugin as L, type MetaData as M, type PageData as P, type ResolvedLoaderConfig as R, type Source as S, type VirtualFile as V, type _ConfigUnion_ as _, type SourceConfig as a, type LoaderConfig as b, type LoaderOptions as c, type Page as d, type Meta as e, type LoaderOutput as f, createGetUrl as g, type InferMetaType as h, type PageTreeBuilderContext as i, type PageTreeTransformer as j, type PageTreeOptions as k, loader as l, multiple as m, type PageTreeBuilder as n, createPageTreeBuilder as o, type ContentStorageFile as p, buildContentStorage as q, type LoaderPluginOption as r, source as s, buildPlugins as t, update as u };