mirror of
https://github.com/hanzo-docs/docs.git
synced 2026-10-25 04:20:02 +00:00
MDX: ready to release
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'fumadocs-ui': patch
|
||||
---
|
||||
|
||||
Fix border styles
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'fumadocs-mdx': patch
|
||||
---
|
||||
|
||||
Fix Fumadocs 14 compatibility issues
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'fumadocs-mdx': minor
|
||||
---
|
||||
|
||||
Improve performance, remove unused imports
|
||||
@@ -6,6 +6,10 @@ import type { LoadedConfig } from '@/utils/load-config';
|
||||
import { remarkInclude } from '@/mdx-plugins/remark-include';
|
||||
import type { defineCollections } from '@/config/define';
|
||||
import type { frontmatterSchema } from '@/utils/schema';
|
||||
import {
|
||||
remarkStructure,
|
||||
type StructuredData,
|
||||
} from 'fumadocs-core/mdx-plugins';
|
||||
|
||||
type T = ReturnType<
|
||||
typeof defineCollections<'doc', typeof frontmatterSchema, true>
|
||||
@@ -39,8 +43,8 @@ export function asyncFiles(
|
||||
...options,
|
||||
remarkPlugins: (v) =>
|
||||
typeof remarkPlugins === 'function'
|
||||
? [remarkInclude, ...remarkPlugins(v)]
|
||||
: [remarkInclude, ...v, ...remarkPlugins],
|
||||
? [remarkInclude, ...remarkPlugins(v), remarkStructure]
|
||||
: [remarkInclude, ...v, ...remarkPlugins, remarkStructure],
|
||||
};
|
||||
}
|
||||
|
||||
@@ -63,10 +67,7 @@ export function asyncFiles(
|
||||
return {
|
||||
body: out.body,
|
||||
toc: out.toc,
|
||||
structuredData: {
|
||||
headings: [],
|
||||
contents: [],
|
||||
},
|
||||
structuredData: out.vfile.data.structuredData as StructuredData,
|
||||
_exports: out.exports ?? {},
|
||||
};
|
||||
},
|
||||
|
||||
@@ -1,16 +1,4 @@
|
||||
import {
|
||||
rehypeCode,
|
||||
type RehypeCodeOptions,
|
||||
rehypeToc,
|
||||
remarkCodeTab,
|
||||
remarkGfm,
|
||||
remarkHeading,
|
||||
type RemarkHeadingOptions,
|
||||
remarkImage,
|
||||
type RemarkImageOptions,
|
||||
remarkStructure,
|
||||
type StructureOptions,
|
||||
} from 'fumadocs-core/mdx-plugins';
|
||||
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';
|
||||
@@ -29,11 +17,11 @@ export type DefaultMDXOptions = Omit<
|
||||
*/
|
||||
valueToExport?: string[];
|
||||
|
||||
remarkStructureOptions?: StructureOptions | false;
|
||||
remarkHeadingOptions?: RemarkHeadingOptions;
|
||||
remarkImageOptions?: RemarkImageOptions | false;
|
||||
remarkStructureOptions?: plugins.StructureOptions | false;
|
||||
remarkHeadingOptions?: plugins.RemarkHeadingOptions;
|
||||
remarkImageOptions?: plugins.RemarkImageOptions | false;
|
||||
remarkCodeTabOptions?: false;
|
||||
rehypeCodeOptions?: RehypeCodeOptions | false;
|
||||
rehypeCodeOptions?: plugins.RehypeCodeOptions | false;
|
||||
};
|
||||
|
||||
function pluginOption(
|
||||
@@ -69,19 +57,22 @@ export function getDefaultMDXOptions({
|
||||
|
||||
const remarkPlugins = pluginOption(
|
||||
(v) => [
|
||||
remarkGfm,
|
||||
plugins.remarkGfm,
|
||||
[
|
||||
remarkHeading,
|
||||
plugins.remarkHeading,
|
||||
{
|
||||
generateToc: false,
|
||||
...remarkHeadingOptions,
|
||||
},
|
||||
],
|
||||
remarkImageOptions !== false && [remarkImage, remarkImageOptions],
|
||||
remarkCodeTabOptions !== false && remarkCodeTab,
|
||||
remarkImageOptions !== false && [plugins.remarkImage, remarkImageOptions],
|
||||
// Fumadocs 14 compatibility
|
||||
'remarkCodeTab' in plugins &&
|
||||
remarkCodeTabOptions !== false &&
|
||||
plugins.remarkCodeTab,
|
||||
...v,
|
||||
remarkStructureOptions !== false && [
|
||||
remarkStructure,
|
||||
plugins.remarkStructure,
|
||||
remarkStructureOptions,
|
||||
],
|
||||
[remarkMdxExport, { values: mdxExports }],
|
||||
@@ -91,9 +82,9 @@ export function getDefaultMDXOptions({
|
||||
|
||||
const rehypePlugins = pluginOption(
|
||||
(v) => [
|
||||
rehypeCodeOptions !== false && [rehypeCode, rehypeCodeOptions],
|
||||
rehypeCodeOptions !== false && [plugins.rehypeCode, rehypeCodeOptions],
|
||||
...v,
|
||||
[rehypeToc],
|
||||
[plugins.rehypeToc],
|
||||
],
|
||||
mdxOptions.rehypePlugins,
|
||||
);
|
||||
|
||||
+3
-24
@@ -1,27 +1,6 @@
|
||||
import { toRuntime, toRuntimeAsync } from "fumadocs-mdx"
|
||||
import fs from "node:fs/promises"
|
||||
import { toRuntime } from "fumadocs-mdx"
|
||||
import * as _source from "./config.ts"
|
||||
import { buildConfig } from "fumadocs-mdx/config"
|
||||
import { remarkInclude } from "fumadocs-mdx/runtime/mdx"
|
||||
import { compileMDX } from "@fumadocs/mdx-remote"
|
||||
import { asyncFiles, buildConfig } from "fumadocs-mdx/runtime/async"
|
||||
const [err, _sourceConfig] = buildConfig(_source)
|
||||
if (err) throw new Error(err)
|
||||
var _temp = _sourceConfig.global?.mdxOptions ?? {}
|
||||
_temp = typeof _temp === "function"? await _temp() : _temp
|
||||
const _temp_remark = _temp.remarkPlugins
|
||||
const _mdxOptions = { ..._temp, remarkPlugins: (v) => typeof _temp_remark === "function"? [remarkInclude, ..._temp_remark(v)] : [remarkInclude, ...v, ...(_temp_remark ?? [])] }
|
||||
export const docs = [toRuntimeAsync({}, async () => {
|
||||
const source = await fs.readFile("$cwd/packages/mdx/test/fixtures/index.mdx")
|
||||
const collection = _sourceConfig.collections.get("docs")
|
||||
const mdxOptions = collection?.mdxOptions ?? _mdxOptions
|
||||
|
||||
const { body, ...res } = await compileMDX({ source: source.toString(), filePath: "$cwd/packages/mdx/test/fixtures/index.mdx", mdxOptions })
|
||||
return { ...res, default: body }
|
||||
}, {"path":"index.mdx","absolutePath":"$cwd/packages/mdx/test/fixtures/index.mdx"}), toRuntimeAsync({}, async () => {
|
||||
const source = await fs.readFile("$cwd/packages/mdx/test/fixtures/folder/test.mdx")
|
||||
const collection = _sourceConfig.collections.get("docs")
|
||||
const mdxOptions = collection?.mdxOptions ?? _mdxOptions
|
||||
|
||||
const { body, ...res } = await compileMDX({ source: source.toString(), filePath: "$cwd/packages/mdx/test/fixtures/folder/test.mdx", mdxOptions })
|
||||
return { ...res, default: body }
|
||||
}, {"path":"folder/test.mdx","absolutePath":"$cwd/packages/mdx/test/fixtures/folder/test.mdx"})];
|
||||
export const docs = asyncFiles([{"frontmatter":{},"file":{"path":"index.mdx","absolutePath":"$cwd/packages/mdx/test/fixtures/index.mdx"}}, {"frontmatter":{},"file":{"path":"folder/test.mdx","absolutePath":"$cwd/packages/mdx/test/fixtures/folder/test.mdx"}}], "docs", _sourceConfig)
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
import { toRuntime, toRuntimeAsync } from "fumadocs-mdx"
|
||||
import { toRuntime } from "fumadocs-mdx"
|
||||
import * as docs_0 from "./index.mdx?collection=docs&hash=hash"
|
||||
import * as docs_1 from "./folder/test.mdx?collection=docs&hash=hash"
|
||||
export const docs = [toRuntime("doc", docs_0, {"path":"index.mdx","absolutePath":"$cwd/packages/mdx/test/fixtures/index.mdx"}), toRuntime("doc", docs_1, {"path":"folder/test.mdx","absolutePath":"$cwd/packages/mdx/test/fixtures/folder/test.mdx"})];
|
||||
Reference in New Issue
Block a user