fix(website): remove several obsolete special handling of dtypes (#10898)

* fix(website): remove several obsolete special handling of dtypes

* fix: reduce hardcoded places

* chore: api-extractor.json setting mainEntryPointName
This commit is contained in:
Qjuh
2025-05-13 20:40:41 +02:00
committed by GitHub
parent aa533efe26
commit 14e226b72b
12 changed files with 49 additions and 94 deletions

View File

@@ -17,24 +17,21 @@ export function EntryPointSelect({
const { entryPoints: parsedEntrypoints } = parseDocsPathParams(params.item as string[] | undefined);
return (
<Select
aria-label="Select an entrypoint"
defaultSelectedKey={parsedEntrypoints.length ? parsedEntrypoints.join('/') : 'global'}
>
<Select aria-label="Select an entrypoint" defaultSelectedKey={parsedEntrypoints.join('/')}>
<SelectTrigger className="bg-[#f3f3f4] dark:bg-[#121214]" />
<SelectList classNames={{ popover: 'bg-[#f3f3f4] dark:bg-[#28282d]' }} items={entryPoints}>
{(item) => (
<SelectOption
className="dark:pressed:bg-[#313135] bg-[#f3f3f4] dark:bg-[#28282d] dark:hover:bg-[#313135]"
href={`/docs/packages/${params.packageName}/${params.version}/${item.entryPoint}`}
id={item.entryPoint || 'global'}
key={item.entryPoint || 'global'}
id={item.entryPoint}
key={item.entryPoint}
onHoverStart={() =>
router.prefetch(`/docs/packages/${params.packageName}/${params.version}/${item.entryPoint}`)
}
textValue={item.entryPoint || 'global'}
textValue={item.entryPoint}
>
{item.entryPoint || 'global'}
{item.entryPoint}
</SelectOption>
)}
</SelectList>

View File

@@ -1,6 +1,6 @@
import Cloudflare from 'cloudflare';
import { NextResponse, type NextRequest } from 'next/server';
import { PACKAGES } from './util/constants';
import { DEFAULT_ENTRY_POINT, PACKAGES, PACKAGES_WITH_ENTRY_POINTS } from './util/constants';
import { ENV } from './util/env';
const client = new Cloudflare({
@@ -8,7 +8,12 @@ const client = new Cloudflare({
});
async function fetchLatestVersion(packageName: string): Promise<string> {
const hasEntryPoints = PACKAGES_WITH_ENTRY_POINTS.includes(packageName);
if (ENV.IS_LOCAL_DEV) {
if (hasEntryPoints) {
return ['main', ...DEFAULT_ENTRY_POINT].join('/');
}
return 'main';
}
@@ -19,7 +24,7 @@ async function fetchLatestVersion(packageName: string): Promise<string> {
params: [packageName],
});
return (result[0]?.results as { version: string }[] | undefined)?.[0]?.version ?? 'main';
return `${(result[0]?.results as { version: string }[] | undefined)?.[0]?.version ?? 'main'}${hasEntryPoints ? ['', ...DEFAULT_ENTRY_POINT].join('/') : ''}`;
} catch {
return '';
}

View File

@@ -16,5 +16,7 @@ export const PACKAGES = [
export const PACKAGES_WITH_ENTRY_POINTS = ['discord-api-types'];
export const DEFAULT_ENTRY_POINT = ['v10'];
export const DESCRIPTION =
"discord.js is a powerful Node.js module that allows you to interact with the Discord API very easily. It takes a much more object-oriented approach than most other JS Discord libraries, making your bot's code significantly tidier and easier to comprehend.";

View File

@@ -1,3 +1,5 @@
import { DEFAULT_ENTRY_POINT } from './constants';
export function parseDocsPathParams(item: string[] | undefined): {
entryPoints: string[];
foundItem: string | undefined;
@@ -10,7 +12,7 @@ export function parseDocsPathParams(item: string[] | undefined): {
const hasTypeMarker = lastElement?.includes('%3A');
return {
entryPoints: hasTypeMarker ? item.slice(0, -1) : item,
entryPoints: hasTypeMarker ? item.slice(0, -1) : lastElement?.length === 0 ? DEFAULT_ENTRY_POINT : item,
foundItem: hasTypeMarker ? lastElement : undefined,
};
}