mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-13 01:53:30 +01:00
feat(website): render syntax and mdx on the server (#9086)
This commit is contained in:
@@ -4,6 +4,7 @@ import type { LinkProps } from 'next/link';
|
||||
import Link from 'next/link';
|
||||
import { usePathname } from 'next/navigation';
|
||||
import type { PropsWithChildren } from 'react';
|
||||
import { useCurrentPathMeta } from '~/hooks/useCurrentPathMeta';
|
||||
|
||||
export interface ItemLinkProps
|
||||
extends Omit<LinkProps, 'href'>,
|
||||
@@ -15,6 +16,11 @@ export interface ItemLinkProps
|
||||
* The URI of the api item to link to. (e.g. `/RestManager`)
|
||||
*/
|
||||
itemURI: string;
|
||||
|
||||
/**
|
||||
* The name of the package the item belongs to.
|
||||
*/
|
||||
packageName?: string | undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -26,17 +32,13 @@ export interface ItemLinkProps
|
||||
*/
|
||||
export function ItemLink(props: PropsWithChildren<ItemLinkProps>) {
|
||||
const path = usePathname();
|
||||
const { packageName, version } = useCurrentPathMeta();
|
||||
|
||||
if (!path) {
|
||||
throw new Error('ItemLink must be used inside a Next.js page. (e.g. /docs/packages/foo/main)');
|
||||
}
|
||||
|
||||
// Check if the item is already in the current path, if so keep the current path
|
||||
const end = path?.split('/')?.length < 6 ? path?.length : -1;
|
||||
const { itemURI, packageName: pkgName, ...linkProps } = props;
|
||||
|
||||
const pathPrefix = path?.split('/').slice(0, end).join('/');
|
||||
|
||||
const { itemURI, ...linkProps } = props;
|
||||
|
||||
return <Link href={`${pathPrefix}${itemURI}`} {...linkProps} />;
|
||||
return <Link href={`/docs/packages/${pkgName ?? packageName}/${version}/${itemURI}`} {...linkProps} />;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user