mirror of
https://github.com/hanzo-docs/docs.git
synced 2026-10-26 10:55:57 +00:00
MDX: Include frontmatter into page.data.content by default
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'fumadocs-mdx': patch
|
||||
---
|
||||
|
||||
Include frontmatter into `page.data.content` by default
|
||||
@@ -17,10 +17,9 @@ export async function getLLMText(page: InferPageType<typeof source>) {
|
||||
value: page.data.content,
|
||||
});
|
||||
|
||||
// note: it doesn't escape frontmatter, it's up to you.
|
||||
return `# ${page.data.title}
|
||||
URL: ${page.url}
|
||||
|
||||
${page.data.description}
|
||||
|
||||
${processed.value}`;
|
||||
}
|
||||
|
||||
@@ -132,7 +132,7 @@ export async function generateJS(
|
||||
info: file,
|
||||
lastModified,
|
||||
data: data as Record<string, unknown>,
|
||||
content: parsed.content,
|
||||
content: { body: parsed.content, matter: parsed.matter },
|
||||
} satisfies AsyncRuntimeFile);
|
||||
});
|
||||
|
||||
|
||||
@@ -26,10 +26,12 @@ export const _runtimeAsync: RuntimeAsync = {
|
||||
return {
|
||||
...data,
|
||||
_file: file,
|
||||
content,
|
||||
get content() {
|
||||
return `${content.matter}${content.body}`;
|
||||
},
|
||||
async load() {
|
||||
const mdxOptions = await initMdxOptions;
|
||||
const out = await buildMDX(collection, content, {
|
||||
const out = await buildMDX(collection, content.body, {
|
||||
...mdxOptions,
|
||||
development: false,
|
||||
frontmatter: data as Record<string, unknown>,
|
||||
|
||||
@@ -39,7 +39,7 @@ export interface RuntimeFile {
|
||||
export interface AsyncRuntimeFile {
|
||||
info: FileInfo;
|
||||
data: Record<string, unknown>;
|
||||
content: string;
|
||||
content: { matter: string; body: string };
|
||||
lastModified?: Date;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
import { load } from 'js-yaml';
|
||||
|
||||
interface Output {
|
||||
/**
|
||||
* The matter section, including the delimiter.
|
||||
*/
|
||||
matter: string;
|
||||
content: string;
|
||||
data: unknown;
|
||||
@@ -22,10 +25,10 @@ export function fumaMatter(input: string): Output {
|
||||
}
|
||||
|
||||
// get the raw front-matter block
|
||||
output.matter = match[1];
|
||||
output.matter = match[0];
|
||||
output.content = input.slice(match[0].length);
|
||||
|
||||
const loaded = load(output.matter);
|
||||
const loaded = load(match[1]);
|
||||
output.data = loaded ?? {};
|
||||
|
||||
return output;
|
||||
|
||||
+1
-1
@@ -3,4 +3,4 @@ import { _runtimeAsync, buildConfig } from "fumadocs-mdx/runtime/async"
|
||||
const _sourceConfig = buildConfig(_source)
|
||||
import { _runtime } from "fumadocs-mdx"
|
||||
import * as _source from "./config"
|
||||
export const docs = _runtimeAsync.doc<typeof _source.docs>([{"info":{"path":"index.mdx","absolutePath":"$cwd/packages/mdx/test/fixtures/index.mdx"},"data":{},"content":"# Hello World\n"}, {"info":{"path":"folder/test.mdx","absolutePath":"$cwd/packages/mdx/test/fixtures/folder/test.mdx"},"data":{},"content":""}], "docs", _sourceConfig)
|
||||
export const docs = _runtimeAsync.doc<typeof _source.docs>([{"info":{"path":"index.mdx","absolutePath":"$cwd/packages/mdx/test/fixtures/index.mdx"},"data":{},"content":{"body":"# Hello World\n","matter":""}}, {"info":{"path":"folder/test.mdx","absolutePath":"$cwd/packages/mdx/test/fixtures/folder/test.mdx"},"data":{},"content":{"body":"","matter":""}}], "docs", _sourceConfig)
|
||||
@@ -93,8 +93,11 @@ test('parse frontmatter', () => {
|
||||
"description": "I love Fumadocs",
|
||||
"title": "hello world",
|
||||
},
|
||||
"matter": "title: hello world
|
||||
description: I love Fumadocs",
|
||||
"matter": "---
|
||||
title: hello world
|
||||
description: I love Fumadocs
|
||||
---
|
||||
",
|
||||
}
|
||||
`);
|
||||
|
||||
@@ -109,8 +112,11 @@ test('parse frontmatter', () => {
|
||||
"description": "I love Fumadocs",
|
||||
"title": "hello world",
|
||||
},
|
||||
"matter": "title: hello world
|
||||
description: I love Fumadocs",
|
||||
"matter": "---
|
||||
title: hello world
|
||||
description: I love Fumadocs
|
||||
---
|
||||
",
|
||||
}
|
||||
`);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user