mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-15 19:13:31 +01:00
feat(IRS): next IRS
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
/* eslint-disable @typescript-eslint/no-throw-literal */
|
||||
import type { GetStaticPaths, GetStaticProps, InferGetStaticPropsType } from 'next/types';
|
||||
import type { GetStaticPaths, GetStaticProps } from 'next/types';
|
||||
import type { DocClass } from '~/DocModel/DocClass';
|
||||
import type { DocEnum } from '~/DocModel/DocEnum';
|
||||
import type { DocFunction } from '~/DocModel/DocFunction';
|
||||
import type { DocInterface } from '~/DocModel/DocInterface';
|
||||
import type { DocTypeAlias } from '~/DocModel/DocTypeAlias';
|
||||
import type { DocVariable } from '~/DocModel/DocVariable';
|
||||
import { ItemSidebar } from '~/components/ItemSidebar';
|
||||
import { ItemSidebar, type ItemListProps } from '~/components/ItemSidebar';
|
||||
import { Class } from '~/components/model/Class';
|
||||
import { Enum } from '~/components/model/Enum';
|
||||
import { Function } from '~/components/model/Function';
|
||||
@@ -17,14 +17,31 @@ import { findMember } from '~/model.server';
|
||||
import { createApiModel } from '~/util/api-model.server';
|
||||
import { findPackage, getMembers } from '~/util/parse.server';
|
||||
|
||||
export const getStaticPaths: GetStaticPaths = () => {
|
||||
export const getStaticPaths: GetStaticPaths = async () => {
|
||||
const packages = ['builders', 'collection', 'proxy', 'rest', 'voice'];
|
||||
|
||||
const pkgs = (
|
||||
await Promise.all(
|
||||
packages.map(async (packageName) => {
|
||||
if (packageName === 'rest') {
|
||||
return { params: { slug: ['main', 'packages', packageName, ''] } };
|
||||
}
|
||||
|
||||
const res = await fetch(`https://docs.discordjs.dev/docs/${packageName}/main.api.json`);
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
const data = await res.json();
|
||||
|
||||
const model = createApiModel(data);
|
||||
const pkg = findPackage(model, packageName);
|
||||
|
||||
return getMembers(pkg!).map((member) => ({ params: { slug: ['main', 'packages', packageName, member.name] } }));
|
||||
}),
|
||||
)
|
||||
).flat();
|
||||
|
||||
return {
|
||||
paths: packages.map((pkg) => ({
|
||||
params: { slug: [pkg] },
|
||||
})),
|
||||
fallback: 'blocking',
|
||||
paths: pkgs,
|
||||
fallback: true,
|
||||
};
|
||||
};
|
||||
|
||||
@@ -35,8 +52,7 @@ export const getStaticProps: GetStaticProps = async ({ params }) => {
|
||||
status: 404,
|
||||
});
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
||||
const res = await fetch(`https://docs.discordjs.dev/docs/${packageName}/${branchName}.api.json`);
|
||||
const res = await fetch(`https://docs.discordjs.dev/docs/${packageName!}/${branchName!}.api.json`);
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
const data = await res.json().catch(() => {
|
||||
throw UnknownResponse;
|
||||
@@ -51,8 +67,11 @@ export const getStaticProps: GetStaticProps = async ({ params }) => {
|
||||
|
||||
return {
|
||||
props: {
|
||||
members: getMembers(pkg),
|
||||
member: findMember(model, packageName!, memberName!)!.toJSON(),
|
||||
packageName,
|
||||
data: {
|
||||
members: getMembers(pkg),
|
||||
member: memberName ? findMember(model, packageName!, memberName)!.toJSON() : null,
|
||||
},
|
||||
},
|
||||
};
|
||||
};
|
||||
@@ -77,13 +96,13 @@ const member = (props: any) => {
|
||||
}
|
||||
};
|
||||
|
||||
export default function Slug(props: InferGetStaticPropsType<typeof getStaticProps>) {
|
||||
export default function Slug(props: Partial<ItemListProps & { data: { member: ReturnType<typeof findMember> } }>) {
|
||||
return (
|
||||
<div className="flex flex-col lg:flex-row overflow-hidden max-w-full h-full bg-white dark:bg-dark">
|
||||
<div className="w-full lg:min-w-1/4 lg:max-w-1/4">
|
||||
<ItemSidebar packageName={props.packageName} data={props} />
|
||||
{props.packageName && props.data ? <ItemSidebar packageName={props.packageName} data={props.data} /> : null}
|
||||
</div>
|
||||
<div className="max-h-full grow overflow-auto">{props.member ? member(props.member) : null}</div>
|
||||
<div className="max-h-full grow overflow-auto">{props.data?.member ? member(props.data.member) : null}</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user