mirror of
https://github.com/hanzo-docs/docs.git
synced 2026-10-26 06:31:49 +00:00
CLI & CC: Fix Content Collections compatibility
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
---
|
||||
'@fumadocs/content-collections': patch
|
||||
'create-fumadocs-app': patch
|
||||
---
|
||||
|
||||
Fix Content Collections compatibility
|
||||
@@ -17,6 +17,7 @@ const metas = defineCollection({
|
||||
name: 'meta',
|
||||
directory: 'content/docs',
|
||||
include: '**/meta.json',
|
||||
parser: 'json',
|
||||
schema: createMetaSchema,
|
||||
});
|
||||
|
||||
|
||||
+1
-17
@@ -32,21 +32,5 @@
|
||||
"typescript": "^5.5.2",
|
||||
"vitest": "^1.6.0"
|
||||
},
|
||||
"packageManager": "[email protected]",
|
||||
"pnpm": {
|
||||
"peerDependencyRules": {
|
||||
"ignoreMissing": [
|
||||
"esbuild",
|
||||
"next"
|
||||
]
|
||||
},
|
||||
"overrides": {
|
||||
"@opentelemetry/api": "^1.4.1",
|
||||
"@types/mdast": "^4.0.3",
|
||||
"mdx-bundler": "^10.0.1",
|
||||
"remark-parse": "^11.0.0",
|
||||
"remark-rehype": "^11.0.0",
|
||||
"unified": "^11.0.4"
|
||||
}
|
||||
}
|
||||
"packageManager": "[email protected]"
|
||||
}
|
||||
|
||||
@@ -45,15 +45,15 @@
|
||||
"types:check": "tsc --noEmit"
|
||||
},
|
||||
"dependencies": {
|
||||
"rehype-img-size": "^1.0.1",
|
||||
"zod": "^3.23.8"
|
||||
"rehype-img-size": "^1.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@content-collections/core": "^0.6.0",
|
||||
"@content-collections/mdx": "^0.1.3",
|
||||
"eslint-config-custom": "workspace:*",
|
||||
"fumadocs-core": "workspace:*",
|
||||
"tsconfig": "workspace:*"
|
||||
"tsconfig": "workspace:*",
|
||||
"zod": "^3.23.8"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"@content-collections/core": "0.x.x",
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
import type { Context, Meta } from '@content-collections/core';
|
||||
import {
|
||||
compileMDX,
|
||||
compileMDX as baseCompileMDX,
|
||||
type Options as MDXOptions,
|
||||
} from '@content-collections/mdx';
|
||||
import {
|
||||
@@ -17,21 +17,30 @@ import {
|
||||
import { type z as Zod } from 'zod';
|
||||
import rehypeImgSize from 'rehype-img-size';
|
||||
|
||||
export interface TransformOptions extends MDXOptions {
|
||||
/**
|
||||
* Generate `structuredData`
|
||||
*
|
||||
* @defaultValue true
|
||||
*/
|
||||
generateStructuredData?: boolean;
|
||||
}
|
||||
|
||||
export type SerializableTOC = {
|
||||
title: string;
|
||||
url: string;
|
||||
depth: number;
|
||||
}[];
|
||||
|
||||
export async function transformMDX<
|
||||
D extends {
|
||||
_meta: Meta;
|
||||
content: string;
|
||||
},
|
||||
>(
|
||||
interface BaseDoc {
|
||||
_meta: Meta;
|
||||
content: string;
|
||||
}
|
||||
|
||||
export async function transformMDX<D extends BaseDoc>(
|
||||
document: D,
|
||||
context: Context,
|
||||
options: MDXOptions = {},
|
||||
options: TransformOptions = {},
|
||||
): Promise<
|
||||
D & {
|
||||
body: string;
|
||||
@@ -43,37 +52,67 @@ export async function transformMDX<
|
||||
structuredData: any;
|
||||
}
|
||||
> {
|
||||
let data: Record<string, unknown> = {};
|
||||
const body = await compileMDX(context, document, {
|
||||
...options,
|
||||
remarkPlugins: [
|
||||
remarkGfm,
|
||||
remarkHeading,
|
||||
...(options.remarkPlugins ?? []),
|
||||
remarkStructure,
|
||||
() => {
|
||||
return (_, file) => {
|
||||
data = file.data;
|
||||
};
|
||||
},
|
||||
],
|
||||
const { generateStructuredData = true, ...rest } = options;
|
||||
|
||||
return context.cache(
|
||||
{
|
||||
type: 'fumadocs',
|
||||
document,
|
||||
},
|
||||
async () => {
|
||||
let data: Record<string, unknown> = {};
|
||||
|
||||
const body = await compileMDX(
|
||||
document,
|
||||
{
|
||||
...context,
|
||||
// avoid nested caching
|
||||
cache: async (input, fn) => fn(input),
|
||||
},
|
||||
{
|
||||
...rest,
|
||||
remarkPlugins: [
|
||||
...(rest.remarkPlugins ?? []),
|
||||
...(generateStructuredData ? [remarkStructure] : []),
|
||||
() => {
|
||||
return (_, file) => {
|
||||
data = file.data;
|
||||
};
|
||||
},
|
||||
],
|
||||
},
|
||||
);
|
||||
|
||||
return {
|
||||
...document,
|
||||
toc: data.toc as SerializableTOC,
|
||||
structuredData: data.structuredData,
|
||||
body,
|
||||
};
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
export async function compileMDX(
|
||||
document: BaseDoc,
|
||||
context: Context,
|
||||
options: MDXOptions = {},
|
||||
): Promise<string> {
|
||||
const { remarkPlugins = [], rehypePlugins = [], ...rest } = options;
|
||||
|
||||
return baseCompileMDX(context, document, {
|
||||
...rest,
|
||||
remarkPlugins: [remarkGfm, remarkHeading, ...remarkPlugins],
|
||||
rehypePlugins: [
|
||||
rehypeCode,
|
||||
[rehypeImgSize, { dir: './public' }],
|
||||
...(options.rehypePlugins ?? []),
|
||||
...(rehypePlugins ?? []),
|
||||
],
|
||||
});
|
||||
|
||||
return {
|
||||
...document,
|
||||
toc: data.toc as SerializableTOC,
|
||||
structuredData: data.structuredData,
|
||||
body,
|
||||
};
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type -- The type is dynamically generated by Zod
|
||||
export function createDocSchema(z: typeof Zod) {
|
||||
export function createDocSchema<Z extends typeof Zod>(z: Z) {
|
||||
return {
|
||||
title: z.string(),
|
||||
description: z.string().optional(),
|
||||
@@ -83,7 +122,7 @@ export function createDocSchema(z: typeof Zod) {
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type -- The type is dynamically generated by Zod
|
||||
export function createMetaSchema(z: typeof Zod) {
|
||||
export function createMetaSchema<Z extends typeof Zod>(z: Z) {
|
||||
return {
|
||||
title: z.string().optional(),
|
||||
pages: z.array(z.string()).optional(),
|
||||
|
||||
@@ -17,6 +17,7 @@ const metas = defineCollection({
|
||||
name: 'meta',
|
||||
directory: 'content/docs',
|
||||
include: '**/meta.json',
|
||||
parser: 'json',
|
||||
schema: createMetaSchema,
|
||||
});
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
{"fumadocs-core":"12.3.4","fumadocs-ui":"12.3.4","fumadocs-mdx":"8.2.33","@fumadocs/content-collections":"0.0.0"}
|
||||
{"fumadocs-core":"12.3.5","fumadocs-ui":"12.3.5","fumadocs-mdx":"8.2.33","@fumadocs/content-collections":"1.0.0"}
|
||||
Generated
+8
-16
@@ -4,14 +4,6 @@ settings:
|
||||
autoInstallPeers: true
|
||||
excludeLinksFromLockfile: false
|
||||
|
||||
overrides:
|
||||
'@opentelemetry/api': ^1.4.1
|
||||
remark-rehype: ^11.0.0
|
||||
'@types/mdast': ^4.0.3
|
||||
remark-parse: ^11.0.0
|
||||
unified: ^11.0.4
|
||||
mdx-bundler: ^10.0.1
|
||||
|
||||
importers:
|
||||
|
||||
.:
|
||||
@@ -333,9 +325,6 @@ importers:
|
||||
rehype-img-size:
|
||||
specifier: ^1.0.1
|
||||
version: 1.0.1
|
||||
zod:
|
||||
specifier: ^3.23.8
|
||||
version: 3.23.8
|
||||
devDependencies:
|
||||
'@content-collections/core':
|
||||
specifier: ^0.6.0
|
||||
@@ -352,6 +341,9 @@ importers:
|
||||
tsconfig:
|
||||
specifier: workspace:*
|
||||
version: link:../tsconfig
|
||||
zod:
|
||||
specifier: ^3.23.8
|
||||
version: 3.23.8
|
||||
|
||||
packages/core:
|
||||
dependencies:
|
||||
@@ -450,7 +442,7 @@ importers:
|
||||
specifier: workspace:*
|
||||
version: link:../tsconfig
|
||||
unified:
|
||||
specifier: ^11.0.4
|
||||
specifier: ^11.0.5
|
||||
version: 11.0.5
|
||||
|
||||
packages/create-app:
|
||||
@@ -566,7 +558,7 @@ importers:
|
||||
specifier: workspace:*
|
||||
version: link:../tsconfig
|
||||
unified:
|
||||
specifier: ^11.0.4
|
||||
specifier: ^11.0.5
|
||||
version: 11.0.5
|
||||
|
||||
packages/eslint-config-custom: {}
|
||||
@@ -617,7 +609,7 @@ importers:
|
||||
specifier: workspace:*
|
||||
version: link:../tsconfig
|
||||
unified:
|
||||
specifier: ^11.0.4
|
||||
specifier: ^11.0.5
|
||||
version: 11.0.5
|
||||
webpack:
|
||||
specifier: ^5.90.3
|
||||
@@ -684,7 +676,7 @@ importers:
|
||||
specifier: workspace:*
|
||||
version: link:../tsconfig
|
||||
unified:
|
||||
specifier: ^11.0.4
|
||||
specifier: ^11.0.5
|
||||
version: 11.0.5
|
||||
vfile:
|
||||
specifier: ^6.0.1
|
||||
@@ -4738,7 +4730,7 @@ packages:
|
||||
engines: {node: '>=18.17.0'}
|
||||
hasBin: true
|
||||
peerDependencies:
|
||||
'@opentelemetry/api': ^1.4.1
|
||||
'@opentelemetry/api': ^1.1.0
|
||||
'@playwright/test': ^1.41.2
|
||||
react: ^18.2.0
|
||||
react-dom: ^18.2.0
|
||||
|
||||
Reference in New Issue
Block a user