mirror of
https://github.com/hanzo-docs/docs.git
synced 2026-10-26 23:49:51 +00:00
MDX: Support customising included files in the map file
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"fumadocs-mdx": patch
|
||||
---
|
||||
|
||||
Support customising included files in the map file
|
||||
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"fumadocs-core": patch
|
||||
---
|
||||
|
||||
Improve remark plugin typings
|
||||
+29
-22
@@ -60,6 +60,11 @@ export interface CreateMDXOptions {
|
||||
* @defaultValue `'./content'`
|
||||
*/
|
||||
rootContentPath?: string;
|
||||
|
||||
/**
|
||||
* {@link LoaderOptions.include}
|
||||
*/
|
||||
include?: string | string[];
|
||||
}
|
||||
|
||||
function pluginOption(
|
||||
@@ -89,29 +94,29 @@ function getMDXLoaderOptions({
|
||||
...valueToExport,
|
||||
];
|
||||
|
||||
const remarkPlugins = pluginOption(
|
||||
(v) => [
|
||||
remarkGfm,
|
||||
remarkHeading,
|
||||
...(remarkImageOptions === false
|
||||
? []
|
||||
: [[remarkImage, remarkImageOptions] satisfies Pluggable]),
|
||||
...v,
|
||||
remarkStructure,
|
||||
[remarkMdxExport, { values: mdxExports }],
|
||||
],
|
||||
mdxOptions.remarkPlugins,
|
||||
);
|
||||
const remarkPlugins = pluginOption((v) => {
|
||||
const plugins: Pluggable[] = [remarkGfm, remarkHeading];
|
||||
|
||||
const rehypePlugins: PluggableList = pluginOption(
|
||||
(v) => [
|
||||
...(rehypeCodeOptions === false
|
||||
? []
|
||||
: [[rehypeCode, rehypeCodeOptions] satisfies Pluggable]),
|
||||
...v,
|
||||
],
|
||||
mdxOptions.rehypePlugins,
|
||||
);
|
||||
if (remarkImageOptions !== false)
|
||||
plugins.push([remarkImage, remarkImageOptions]);
|
||||
|
||||
plugins.push(...v, remarkStructure, [
|
||||
remarkMdxExport,
|
||||
{ values: mdxExports },
|
||||
]);
|
||||
|
||||
return plugins;
|
||||
}, mdxOptions.remarkPlugins);
|
||||
|
||||
const rehypePlugins: PluggableList = pluginOption((v) => {
|
||||
const plugins: Pluggable[] = [...v];
|
||||
|
||||
if (rehypeCodeOptions !== false) {
|
||||
plugins.unshift([rehypeCode, rehypeCodeOptions]);
|
||||
}
|
||||
|
||||
return plugins;
|
||||
}, mdxOptions.rehypePlugins);
|
||||
|
||||
return {
|
||||
providerImportSource: 'next-mdx-import-source-file',
|
||||
@@ -128,6 +133,7 @@ const createMDX =
|
||||
rootMapPath = './.map.ts',
|
||||
rootContentPath = './content',
|
||||
buildSearchIndex = false,
|
||||
...loadOptions
|
||||
}: CreateMDXOptions = {}) =>
|
||||
(nextConfig: NextConfig = {}) => {
|
||||
const rootMapFile = path.resolve(cwd, rootMapPath);
|
||||
@@ -169,6 +175,7 @@ const createMDX =
|
||||
options: {
|
||||
rootContentDir,
|
||||
rootMapFile,
|
||||
...loadOptions,
|
||||
} satisfies LoaderOptions,
|
||||
},
|
||||
},
|
||||
|
||||
@@ -5,6 +5,13 @@ import type { LoaderContext } from 'webpack';
|
||||
export interface LoaderOptions {
|
||||
rootContentDir: string;
|
||||
rootMapFile: string;
|
||||
|
||||
/**
|
||||
* Included files in the map file
|
||||
*
|
||||
* @defaultValue './**/*.{md,mdx,json}'
|
||||
*/
|
||||
include?: string | string[];
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -23,10 +30,14 @@ export default function loader(
|
||||
callback(null, buildMap(options));
|
||||
}
|
||||
|
||||
function buildMap({ rootContentDir, rootMapFile }: LoaderOptions): string {
|
||||
function buildMap({
|
||||
rootContentDir,
|
||||
rootMapFile,
|
||||
include = ['./**/*.{md,mdx,json}'],
|
||||
}: LoaderOptions): string {
|
||||
const mapDir = path.dirname(rootMapFile);
|
||||
|
||||
const files = fg.sync('./**/*.{md,mdx,json}', {
|
||||
const files = fg.sync(include, {
|
||||
cwd: rootContentDir,
|
||||
});
|
||||
|
||||
|
||||
@@ -21,6 +21,9 @@ export interface SearchIndex {
|
||||
}
|
||||
|
||||
export interface Options {
|
||||
rootContentDir: string;
|
||||
rootMapFile: string;
|
||||
|
||||
/**
|
||||
* Only build search indexes in production builds
|
||||
*
|
||||
@@ -28,13 +31,6 @@ export interface Options {
|
||||
*/
|
||||
productionOnly?: boolean;
|
||||
|
||||
/**
|
||||
* Absolute path of root content directory
|
||||
*/
|
||||
rootContentDir: string;
|
||||
|
||||
rootMapFile: string;
|
||||
|
||||
/**
|
||||
* @param path - MDX file path relative to root content dir
|
||||
* @returns page URL
|
||||
|
||||
Reference in New Issue
Block a user