mirror of
https://github.com/hanzo-docs/docs.git
synced 2026-10-26 23:49:51 +00:00
MDX: Fix remark-mdx-exports plugin fallback
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'fumadocs-mdx': patch
|
||||
---
|
||||
|
||||
Fix `remark-mdx-exports` plugin fallback
|
||||
@@ -15,7 +15,7 @@ interface Options {
|
||||
function remarkMdxExport({ values }: Options): Transformer<Root, Root> {
|
||||
return (tree, vfile) => {
|
||||
for (const name of values) {
|
||||
if (!(name in vfile.data)) return;
|
||||
if (!(name in vfile.data)) continue;
|
||||
|
||||
// @ts-expect-error -- It is a node
|
||||
tree.children.unshift(getMdastExport(name, vfile.data[name]));
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
import type { Transformer } from 'unified';
|
||||
import type { Root } from 'mdast';
|
||||
import { visit } from 'unist-util-visit';
|
||||
|
||||
declare module 'vfile' {
|
||||
interface DataMap {
|
||||
extractedReferences: ExtractedReference[];
|
||||
}
|
||||
}
|
||||
|
||||
export interface ExtractedReference {
|
||||
href: string;
|
||||
}
|
||||
|
||||
export function remarkExtract(): Transformer<Root, Root> {
|
||||
return (tree, file) => {
|
||||
const urls: ExtractedReference[] = [];
|
||||
visit(tree, 'link', (node) => {
|
||||
urls.push({
|
||||
href: node.url,
|
||||
});
|
||||
|
||||
return 'skip';
|
||||
});
|
||||
|
||||
file.data.extractedReferences = urls;
|
||||
};
|
||||
}
|
||||
@@ -56,7 +56,7 @@ export function remarkInclude(this: Processor): Transformer<Root, Root> {
|
||||
this: Processor,
|
||||
tree: Root,
|
||||
directory: string,
|
||||
data: DataMap,
|
||||
data: Partial<DataMap>,
|
||||
) {
|
||||
const queue: Promise<void>[] = [];
|
||||
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
||||
import type { MetaData, PageData, Source } from 'fumadocs-core/source';
|
||||
import type { LoadedConfig } from '@/utils/config';
|
||||
import type { FC } from 'react';
|
||||
import type { MDXProps } from 'mdx/types';
|
||||
import type { StructuredData } from 'fumadocs-core/mdx-plugins';
|
||||
import type { TableOfContents } from 'fumadocs-core/server';
|
||||
import type { DocCollection, DocsCollection, MetaCollection } from '@/config';
|
||||
import type { CompiledMDXProperties } from '@/utils/build-mdx';
|
||||
|
||||
export interface BaseCollectionEntry {
|
||||
/**
|
||||
@@ -19,15 +16,9 @@ export interface FileInfo {
|
||||
absolutePath: string;
|
||||
}
|
||||
|
||||
export interface MarkdownProps {
|
||||
body: FC<MDXProps>;
|
||||
structuredData: StructuredData;
|
||||
toc: TableOfContents;
|
||||
|
||||
/**
|
||||
* Only available when `lastModifiedTime` is enabled on MDX loader
|
||||
*/
|
||||
lastModified?: Date;
|
||||
interface MarkdownProps
|
||||
extends Omit<CompiledMDXProperties, 'frontmatter' | 'default'> {
|
||||
body: CompiledMDXProperties['default'];
|
||||
}
|
||||
|
||||
export interface RuntimeFile {
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
import type { TableOfContents } from 'fumadocs-core/server';
|
||||
import { createElement, type FC, lazy, type ReactNode } from 'react';
|
||||
import type { MDXProps } from 'mdx/types';
|
||||
import type { StructuredData } from 'fumadocs-core/mdx-plugins';
|
||||
import type { DocCollection, DocsCollection, MetaCollection } from '@/config';
|
||||
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
||||
import type {
|
||||
@@ -10,18 +8,7 @@ import type {
|
||||
Source,
|
||||
VirtualFile,
|
||||
} from 'fumadocs-core/source';
|
||||
|
||||
interface CompiledMDXProperties<Frontmatter> {
|
||||
frontmatter: Frontmatter;
|
||||
structuredData: StructuredData;
|
||||
toc: TableOfContents;
|
||||
default: FC<MDXProps>;
|
||||
|
||||
/**
|
||||
* Only available when `lastModifiedTime` is enabled on MDX loader
|
||||
*/
|
||||
lastModified?: Date;
|
||||
}
|
||||
import type { CompiledMDXProperties } from '@/utils/build-mdx';
|
||||
|
||||
export type CompiledMDXFile<Frontmatter> = CompiledMDXProperties<Frontmatter> &
|
||||
Record<string, unknown>;
|
||||
@@ -131,7 +118,7 @@ export function fromConfig<Config>(): {
|
||||
structuredData,
|
||||
lastModified,
|
||||
_exports: entry,
|
||||
};
|
||||
} as MDXFileToPageData<Frontmatter>;
|
||||
}
|
||||
|
||||
function mapPageDataLazy<Frontmatter>(
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
import { createProcessor, type ProcessorOptions } from '@mdx-js/mdx';
|
||||
import type { DataMap, VFile } from 'vfile';
|
||||
import { remarkInclude } from '@/mdx-plugins/remark-include';
|
||||
import type { StructuredData } from 'fumadocs-core/mdx-plugins';
|
||||
import type { TableOfContents } from 'fumadocs-core/server';
|
||||
import type { FC } from 'react';
|
||||
import type { MDXProps } from 'mdx/types';
|
||||
import { ExtractedReference } from '@/mdx-plugins/remark-extract';
|
||||
|
||||
type Processor = ReturnType<typeof createProcessor>;
|
||||
|
||||
@@ -26,6 +31,19 @@ export interface CompilerOptions {
|
||||
addDependency: (file: string) => void;
|
||||
}
|
||||
|
||||
export interface CompiledMDXProperties<Frontmatter = Record<string, unknown>> {
|
||||
frontmatter: Frontmatter;
|
||||
structuredData: StructuredData;
|
||||
toc: TableOfContents;
|
||||
default: FC<MDXProps>;
|
||||
|
||||
/**
|
||||
* Only available when `lastModifiedTime` is enabled on MDX loader
|
||||
*/
|
||||
lastModified?: Date;
|
||||
extractedReferences?: ExtractedReference[];
|
||||
}
|
||||
|
||||
export type { DataMap };
|
||||
|
||||
declare module 'vfile' {
|
||||
|
||||
@@ -2,6 +2,7 @@ import * as plugins from 'fumadocs-core/mdx-plugins';
|
||||
import type { ProcessorOptions } from '@mdx-js/mdx';
|
||||
import type { Pluggable } from 'unified';
|
||||
import remarkMdxExport from '@/mdx-plugins/remark-exports';
|
||||
import { remarkExtract } from '@/mdx-plugins/remark-extract';
|
||||
|
||||
type ResolvePlugins = Pluggable[] | ((v: Pluggable[]) => Pluggable[]);
|
||||
|
||||
@@ -55,6 +56,7 @@ export function getDefaultMDXOptions({
|
||||
}: DefaultMDXOptions): ProcessorOptions {
|
||||
const mdxExports = [
|
||||
'structuredData',
|
||||
'extractedReferences',
|
||||
'frontmatter',
|
||||
'lastModified',
|
||||
...valueToExport,
|
||||
@@ -85,6 +87,7 @@ export function getDefaultMDXOptions({
|
||||
'remarkNpm' in plugins &&
|
||||
remarkNpmOptions !== false && [plugins.remarkNpm, remarkNpmOptions],
|
||||
...v,
|
||||
remarkExtract,
|
||||
remarkStructureOptions !== false && [
|
||||
plugins.remarkStructure,
|
||||
remarkStructureOptions,
|
||||
|
||||
Reference in New Issue
Block a user