mirror of
https://github.com/hanzo-docs/docs.git
synced 2026-10-26 23:49:51 +00:00
MDX: Add page.data.content to sync mode
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'fumadocs-mdx': patch
|
||||
---
|
||||
|
||||
Add `page.data.content` to sync mode
|
||||
@@ -58,6 +58,9 @@ export interface Source<Config extends SourceConfig> {
|
||||
}
|
||||
|
||||
export interface Page<Data = PageData> {
|
||||
/**
|
||||
* Virtualized file path
|
||||
*/
|
||||
file: FileInfo;
|
||||
slugs: string[];
|
||||
url: string;
|
||||
@@ -67,6 +70,9 @@ export interface Page<Data = PageData> {
|
||||
}
|
||||
|
||||
export interface Meta<Data = MetaData> {
|
||||
/**
|
||||
* Virtualized file path
|
||||
*/
|
||||
file: FileInfo;
|
||||
data: Data;
|
||||
}
|
||||
|
||||
@@ -9,12 +9,12 @@ export interface FileInfo {
|
||||
flattenedPath: string;
|
||||
|
||||
/**
|
||||
* Original path of file
|
||||
* path of file (unparsed)
|
||||
*/
|
||||
path: string;
|
||||
|
||||
/**
|
||||
* File name without locale and extension
|
||||
* File name without extension
|
||||
*/
|
||||
name: string;
|
||||
|
||||
|
||||
@@ -37,5 +37,8 @@ export interface MarkdownProps {
|
||||
}
|
||||
|
||||
export interface BaseCollectionEntry {
|
||||
/**
|
||||
* Raw file path of collection entry, including absolute path (not normalized).
|
||||
*/
|
||||
_file: FileInfo;
|
||||
}
|
||||
|
||||
@@ -1,21 +1,27 @@
|
||||
import type { VirtualFile } from 'fumadocs-core/source';
|
||||
import {
|
||||
type MetaData,
|
||||
type PageData,
|
||||
type Source,
|
||||
} from 'fumadocs-core/source';
|
||||
import { type BaseCollectionEntry } from '@/config';
|
||||
import type { VirtualFile } from 'fumadocs-core/source';
|
||||
import type { Runtime } from '@/runtime/types';
|
||||
import fs from 'node:fs';
|
||||
|
||||
export const _runtime: Runtime = {
|
||||
doc(files) {
|
||||
return files.map((file) => {
|
||||
const { default: body, frontmatter, ...exports } = file.data;
|
||||
let cachedContent: string | undefined;
|
||||
|
||||
return {
|
||||
body,
|
||||
...exports,
|
||||
...(frontmatter as object),
|
||||
get content() {
|
||||
cachedContent ??= fs.readFileSync(file.info.absolutePath).toString();
|
||||
return cachedContent;
|
||||
},
|
||||
_exports: file.data,
|
||||
_file: file.info,
|
||||
};
|
||||
|
||||
@@ -14,12 +14,17 @@ export interface AsyncRuntimeFile {
|
||||
content: string;
|
||||
}
|
||||
|
||||
type DocOut<Schema extends StandardSchemaV1> = Omit<
|
||||
MarkdownProps,
|
||||
keyof StandardSchemaV1.InferOutput<Schema>
|
||||
> &
|
||||
StandardSchemaV1.InferOutput<Schema> &
|
||||
BaseCollectionEntry;
|
||||
type DocOut<Schema extends StandardSchemaV1> = Override<
|
||||
MarkdownProps & {
|
||||
/**
|
||||
* Read the original content of file from file system.
|
||||
*/
|
||||
get content(): string;
|
||||
},
|
||||
StandardSchemaV1.InferOutput<Schema> & BaseCollectionEntry
|
||||
>;
|
||||
|
||||
type Override<A, B> = Omit<A, keyof B> & B;
|
||||
|
||||
type MetaOut<Schema extends StandardSchemaV1> =
|
||||
StandardSchemaV1.InferOutput<Schema> & BaseCollectionEntry;
|
||||
|
||||
Reference in New Issue
Block a user