mirror of
https://github.com/hanzo-docs/docs.git
synced 2026-10-26 05:23:40 +00:00
Core: Remove fumadocs-core/server export
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
---
|
||||
'fumadocs-core': major
|
||||
---
|
||||
|
||||
**Remove `fumadocs-core/server` export**
|
||||
|
||||
- **`getGithubLastEdit`:** Moved to `fumadocs-core/content/github`.
|
||||
- **`getTableOfContents`:** Moved to `fumadocs-core/content/toc`.
|
||||
- **`PageTree` and page tree utilities:** Moved to `fumadocs-core/page-tree`.
|
||||
- **`TOCItemType`, `TableOfContents`:** Moved to `fumadocs-core/toc`.
|
||||
- **`createMetadataImage`:** Use the Next.js Metadata API instead.
|
||||
@@ -52,10 +52,6 @@
|
||||
"import": "./dist/search/*.js",
|
||||
"types": "./dist/search/*.d.ts"
|
||||
},
|
||||
"./server": {
|
||||
"import": "./dist/server/index.js",
|
||||
"types": "./dist/server/index.d.ts"
|
||||
},
|
||||
"./source": {
|
||||
"import": "./dist/source/index.js",
|
||||
"types": "./dist/source/index.d.ts"
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
// TODO: replace this with `fumadocs-core/content/github`
|
||||
export * from '@/content/github';
|
||||
|
||||
// removed on next major
|
||||
export * from './metadata';
|
||||
|
||||
// TODO: replace this with 'fumadocs-core/content/toc'
|
||||
export * from '@/content/toc';
|
||||
|
||||
// TODO: replace this with 'fumadocs-core/toc'
|
||||
export type { TOCItemType, TableOfContents } from '@/toc';
|
||||
|
||||
// TODO: replace this with `fumadocs-core/search`
|
||||
export type { SortedResult } from '../search';
|
||||
|
||||
// TODO: replace this with `fumadocs-core/page-tree`
|
||||
export * from '@/page-tree/utils';
|
||||
export type * as PageTree from '@/page-tree/definitions';
|
||||
@@ -1,147 +0,0 @@
|
||||
import type { Metadata } from 'next';
|
||||
import { type NextRequest } from 'next/server';
|
||||
import {
|
||||
type InferPageType,
|
||||
type LoaderConfig,
|
||||
type LoaderOutput,
|
||||
} from '@/source';
|
||||
|
||||
interface ImageMeta {
|
||||
alt: string;
|
||||
url: string;
|
||||
width: number;
|
||||
height: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Use the SEO features of your own React.js framework instead
|
||||
*/
|
||||
export function createMetadataImage<
|
||||
S extends LoaderOutput<LoaderConfig>,
|
||||
>(options: {
|
||||
source: S;
|
||||
|
||||
/**
|
||||
* the route of your OG image generator.
|
||||
*
|
||||
* @example '/docs-og'
|
||||
* @defaultValue '/docs-og'
|
||||
*/
|
||||
imageRoute?: string;
|
||||
|
||||
/**
|
||||
* The filename of generated OG Image
|
||||
*
|
||||
* @defaultValue 'image.png'
|
||||
*/
|
||||
filename?: string;
|
||||
}): {
|
||||
getImageMeta: (slugs: string[]) => ImageMeta;
|
||||
|
||||
/**
|
||||
* Add image meta tags to metadata
|
||||
*/
|
||||
withImage: (slugs: string[], metadata?: Metadata) => Metadata;
|
||||
|
||||
/**
|
||||
* Generate static params for OG Image Generator
|
||||
*/
|
||||
generateParams: () => {
|
||||
slug: string[];
|
||||
lang?: string;
|
||||
}[];
|
||||
|
||||
/**
|
||||
* create route handler for OG Image Generator
|
||||
*/
|
||||
createAPI: (
|
||||
handler: (
|
||||
page: InferPageType<S>,
|
||||
request: NextRequest,
|
||||
options: {
|
||||
params:
|
||||
| {
|
||||
slug: string[];
|
||||
lang?: string;
|
||||
}
|
||||
| Promise<{
|
||||
slug: string[];
|
||||
lang?: string;
|
||||
}>;
|
||||
},
|
||||
) => Response | Promise<Response>,
|
||||
) => (
|
||||
request: NextRequest,
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- ignore Next.js type check
|
||||
options: any,
|
||||
) => Response | Promise<Response>;
|
||||
} {
|
||||
const { filename = 'image.png', imageRoute = '/docs-og' } = options;
|
||||
|
||||
function getImageMeta(slugs: string[]): ImageMeta {
|
||||
return {
|
||||
alt: 'Banner',
|
||||
url: `/${[...imageRoute.split('/'), ...slugs, filename].filter((v) => v.length > 0).join('/')}`,
|
||||
width: 1200,
|
||||
height: 630,
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
getImageMeta,
|
||||
withImage(slugs, data) {
|
||||
const imageData = getImageMeta(slugs);
|
||||
|
||||
return {
|
||||
...data,
|
||||
openGraph: {
|
||||
images: imageData,
|
||||
...data?.openGraph,
|
||||
},
|
||||
twitter: {
|
||||
images: imageData,
|
||||
card: 'summary_large_image',
|
||||
...data?.twitter,
|
||||
},
|
||||
};
|
||||
},
|
||||
generateParams() {
|
||||
return options.source.generateParams().map((params) => ({
|
||||
...params,
|
||||
slug: [...params.slug, filename],
|
||||
}));
|
||||
},
|
||||
createAPI(handler) {
|
||||
return async (req, args) => {
|
||||
const params = await (
|
||||
args as {
|
||||
params?: Promise<Record<string, string | string[] | undefined>>;
|
||||
}
|
||||
).params;
|
||||
|
||||
if (!params || !('slug' in params) || params.slug === undefined)
|
||||
throw new Error(`Invalid params: ${JSON.stringify(params)}`);
|
||||
|
||||
const lang =
|
||||
'lang' in params && typeof params.lang === 'string'
|
||||
? params.lang
|
||||
: undefined;
|
||||
const input: { slug: string[]; lang?: string } = {
|
||||
slug: Array.isArray(params.slug) ? params.slug : [params.slug],
|
||||
lang,
|
||||
};
|
||||
|
||||
const page = options.source.getPage(
|
||||
input.slug.slice(0, -1), //remove filename
|
||||
lang,
|
||||
);
|
||||
if (!page)
|
||||
return new Response(null, {
|
||||
status: 404,
|
||||
});
|
||||
|
||||
return handler(page as InferPageType<S>, req, { params: input });
|
||||
};
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -11,7 +11,7 @@ export default defineConfig({
|
||||
format: 'esm',
|
||||
entry: [
|
||||
'src/{toc,link,breadcrumb,sidebar,dynamic-link,hide-if-empty}.tsx',
|
||||
'src/{server,source,mdx-plugins,page-tree}/index.ts',
|
||||
'src/{source,mdx-plugins,page-tree}/index.ts',
|
||||
'src/{negotiation,content}/*',
|
||||
'src/source/plugins/lucide-icons.ts',
|
||||
'src/search/{index,client,server,algolia,orama-cloud}.ts',
|
||||
|
||||
Reference in New Issue
Block a user