mirror of
https://github.com/hanzo-docs/docs.git
synced 2026-10-26 06:31:49 +00:00
Core: Standardize structuredData in page data
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
---
|
||||
'fumadocs-core': patch
|
||||
'fumadocs-mdx': patch
|
||||
---
|
||||
|
||||
Standardize `structuredData` in page data
|
||||
@@ -231,8 +231,8 @@
|
||||
}
|
||||
},
|
||||
"inlinedDependencies": {
|
||||
"@formatjs/fast-memoize": "3.1.4",
|
||||
"@formatjs/intl-localematcher": "0.8.6",
|
||||
"@formatjs/fast-memoize": "3.1.5",
|
||||
"@formatjs/intl-localematcher": "0.8.8",
|
||||
"@shikijs/transformers": "4.0.2",
|
||||
"image-size": "2.0.2",
|
||||
"negotiator": "1.0.0",
|
||||
|
||||
@@ -24,11 +24,11 @@ export interface SharedIndex {
|
||||
export async function buildIndexDefault(page: Page): Promise<SharedIndex> {
|
||||
let structuredData: StructuredData | undefined;
|
||||
|
||||
if ('structuredData' in page.data) {
|
||||
if (page.data.structuredData) {
|
||||
structuredData =
|
||||
typeof page.data.structuredData === 'function'
|
||||
? ((await page.data.structuredData()) as StructuredData)
|
||||
: (page.data.structuredData as StructuredData);
|
||||
? await page.data.structuredData()
|
||||
: page.data.structuredData;
|
||||
} else if ('load' in page.data && typeof page.data.load === 'function') {
|
||||
structuredData = (await page.data.load()).structuredData;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { Awaitable } from '@/types';
|
||||
import type { DynamicLoader } from './dynamic';
|
||||
import type { StructuredData } from '@/mdx-plugins';
|
||||
|
||||
export type SourceUnion<Config extends SourceConfig = SourceConfig> =
|
||||
| StaticSource<Config>
|
||||
@@ -39,6 +40,8 @@ export interface PageData {
|
||||
icon?: string | undefined;
|
||||
title?: string;
|
||||
description?: string | undefined;
|
||||
|
||||
structuredData?: StructuredData | (() => Awaitable<StructuredData>);
|
||||
}
|
||||
|
||||
export type VirtualFile<Config extends SourceConfig = SourceConfig> =
|
||||
|
||||
@@ -4,6 +4,7 @@ import type { DocCollection, DocsCollection, MetaCollection } from '@/config';
|
||||
import type { StandardSchemaV1 } from '@standard-schema/spec';
|
||||
import type { CompiledMDXProperties } from '@/loaders/mdx/build-mdx';
|
||||
import type { InternalTypeConfig, DocData, DocMethods, FileInfo, MetaMethods } from './types';
|
||||
import type { StructuredData } from 'fumadocs-core/mdx-plugins/remark-structure';
|
||||
|
||||
export type MetaCollectionEntry<Data> = Data & MetaMethods;
|
||||
|
||||
@@ -24,6 +25,7 @@ export type AsyncDocCollectionEntry<
|
||||
TC extends InternalTypeConfig = InternalTypeConfig,
|
||||
> = {
|
||||
load: () => Promise<DocData & TC['DocData'][Name]>;
|
||||
structuredData: () => Promise<StructuredData>;
|
||||
} & DocMethods &
|
||||
Frontmatter;
|
||||
|
||||
@@ -138,6 +140,9 @@ export function server<Config, TC extends InternalTypeConfig>(options: ServerOpt
|
||||
async load() {
|
||||
return mapDocData(await content());
|
||||
},
|
||||
async structuredData() {
|
||||
return (await content()).structuredData;
|
||||
},
|
||||
} satisfies AsyncDocCollectionEntry;
|
||||
}),
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user