mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 09:03:29 +01:00
feat: local and preview detection
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
/* eslint-disable react/no-unknown-property */
|
||||
import { ImageResponse } from 'next/og';
|
||||
import { fetchNode } from '~/util/fetchNode';
|
||||
import { resolveKind } from '~/util/resolveNodeKind';
|
||||
|
||||
export const runtime = 'edge';
|
||||
@@ -16,14 +17,7 @@ export default async function Image({
|
||||
}: {
|
||||
readonly params: { readonly item: string; readonly packageName: string; readonly version: string };
|
||||
}) {
|
||||
const normalizeItem = params.item.split(encodeURIComponent(':')).join('.').toLowerCase();
|
||||
|
||||
const isMainVersion = params.version === 'main';
|
||||
const fileContent = await fetch(
|
||||
`${process.env.BLOB_STORAGE_URL}/rewrite/${params.packageName}/${params.version}.${normalizeItem}.api.json`,
|
||||
{ next: isMainVersion ? { revalidate: 0 } : { revalidate: 604_800 } },
|
||||
);
|
||||
const node = await fileContent.json();
|
||||
const node = await fetchNode({ item: params.item, packageName: params.packageName, version: params.version });
|
||||
|
||||
return new ImageResponse(
|
||||
(
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
// import { readFile } from 'node:fs/promises';
|
||||
// import { join } from 'node:path';
|
||||
// import { inspect } from 'node:util';
|
||||
import type { Metadata } from 'next';
|
||||
import { DocItem } from '~/components/DocItem';
|
||||
import { fetchNode } from '~/util/fetchNode';
|
||||
|
||||
export async function generateMetadata({
|
||||
params,
|
||||
@@ -25,22 +23,7 @@ export default async function Page({
|
||||
}: {
|
||||
readonly params: { readonly item: string; readonly packageName: string; readonly version: string };
|
||||
}) {
|
||||
const normalizeItem = params.item.split(encodeURIComponent(':')).join('.').toLowerCase();
|
||||
|
||||
// const fileContent = await readFile(
|
||||
// join(process.cwd(), `../../packages/${params.packageName}/docs/split/${params.version}.${normalizeItem}.api.json`),
|
||||
// 'utf8',
|
||||
// );
|
||||
// const node = JSON.parse(fileContent);
|
||||
|
||||
const isMainVersion = params.version === 'main';
|
||||
const fileContent = await fetch(
|
||||
`${process.env.BLOB_STORAGE_URL}/rewrite/${params.packageName}/${params.version}.${normalizeItem}.api.json`,
|
||||
{ next: isMainVersion ? { revalidate: 0 } : { revalidate: 604_800 } },
|
||||
);
|
||||
const node = await fileContent.json();
|
||||
|
||||
// console.log(inspect(node, { depth: 0 }));
|
||||
const node = await fetchNode({ item: params.item, packageName: params.packageName, version: params.version });
|
||||
|
||||
return (
|
||||
<main className="flex w-full flex-col gap-8 pb-12 md:pb-0">
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
// import { readFile } from 'node:fs/promises';
|
||||
// import { join } from 'node:path';
|
||||
// import { inspect } from 'node:util';
|
||||
import type { Metadata } from 'next';
|
||||
import dynamic from 'next/dynamic';
|
||||
import type { PropsWithChildren } from 'react';
|
||||
@@ -8,6 +5,8 @@ import { Navigation } from '~/components/Navigation';
|
||||
import { OverlayScrollbarsComponent } from '~/components/OverlayScrollbars';
|
||||
import { Drawer } from '~/components/ui/Drawer';
|
||||
import { Footer } from '~/components/ui/Footer';
|
||||
import { ENV } from '~/util/env';
|
||||
import { fetchDependencies } from '~/util/fetchDependencies';
|
||||
|
||||
// eslint-disable-next-line promise/prefer-await-to-then
|
||||
const CmdK = dynamic(async () => import('~/components/ui/CmdK').then((mod) => mod.CmdK), { ssr: false });
|
||||
@@ -29,30 +28,16 @@ export default async function Layout({
|
||||
params,
|
||||
children,
|
||||
}: PropsWithChildren<{ readonly params: { readonly packageName: string; readonly version: string } }>) {
|
||||
// const fileContent = await readFile(
|
||||
// join(process.cwd(), `../../packages/${params.packageName}/docs/split/${params.version}.dependencies.api.json`),
|
||||
// 'utf8',
|
||||
// );
|
||||
// const dependencies = JSON.parse(fileContent);
|
||||
|
||||
const isMainVersion = params.version === 'main';
|
||||
const fileContent = await fetch(
|
||||
`${process.env.BLOB_STORAGE_URL}/rewrite/${params.packageName}/${params.version}.dependencies.api.json`,
|
||||
{ next: isMainVersion ? { revalidate: 0 } : { revalidate: 604_800 } },
|
||||
);
|
||||
const parsedDependencies = await fileContent.json();
|
||||
const dependencies = Object.entries<string>(parsedDependencies)
|
||||
.filter(([key]) => key.startsWith('@discordjs/') && !key.includes('api-extractor'))
|
||||
.map(([key, value]) => `${key.replace('@discordjs/', '').replaceAll('.', '-')}-${value.replaceAll('.', '-')}`);
|
||||
|
||||
// console.log(inspect(dependencies, { depth: 0 }));
|
||||
const dependencies = await fetchDependencies({ packageName: params.packageName, version: params.version });
|
||||
|
||||
return (
|
||||
// eslint-disable-next-line react/no-unknown-property
|
||||
<div vaul-drawer-wrapper="" className="mx-auto flex max-w-screen-xl flex-col gap-12 p-6 md:flex-row">
|
||||
<div className="sticky top-6 hidden flex-shrink-0 self-start md:block">
|
||||
<div vaul-drawer-wrapper="" className="mx-auto flex max-w-screen-2xl flex-col gap-12 p-6 md:flex-row">
|
||||
<div
|
||||
className={`sticky hidden flex-shrink-0 self-start md:block ${ENV.IS_LOCAL_DEV || ENV.IS_PREVIEW ? 'top-[64px]' : 'top-6'}`}
|
||||
>
|
||||
<OverlayScrollbarsComponent
|
||||
className="max-h-[calc(100dvh-48px)]"
|
||||
className={`${ENV.IS_LOCAL_DEV || ENV.IS_PREVIEW ? 'max-h-[calc(100dvh-48px-40px)]' : 'max-h-[calc(100dvh-48px)]'}`}
|
||||
defer
|
||||
options={{
|
||||
overflow: { x: 'hidden' },
|
||||
|
||||
@@ -23,7 +23,7 @@ export default async function Page({ params }: { readonly params: { readonly pac
|
||||
);
|
||||
|
||||
return (
|
||||
<div className="prose prose-neutral mx-auto max-w-screen-lg dark:prose-invert">
|
||||
<div className="prose prose-neutral mx-auto max-w-screen-xl dark:prose-invert">
|
||||
<MDXRemote
|
||||
options={{
|
||||
mdxOptions: {
|
||||
|
||||
@@ -5,6 +5,7 @@ import type { Metadata, Viewport } from 'next';
|
||||
import type { PropsWithChildren } from 'react';
|
||||
import { LocalizedStringProvider } from 'react-aria-components/i18n';
|
||||
import { DESCRIPTION } from '~/util/constants';
|
||||
import { ENV } from '~/util/env';
|
||||
import { Providers } from './providers';
|
||||
|
||||
import '~/styles/main.css';
|
||||
@@ -80,9 +81,21 @@ export const metadata: Metadata = {
|
||||
export default async function RootLayout({ children }: PropsWithChildren) {
|
||||
return (
|
||||
<html lang="en" className={`${GeistSans.variable} ${GeistMono.variable} antialiased`} suppressHydrationWarning>
|
||||
<body className="bg-white dark:bg-[#121212]">
|
||||
<body className="relative bg-white dark:bg-[#121212]">
|
||||
<LocalizedStringProvider locale="en-US" />
|
||||
<Providers>{children}</Providers>
|
||||
<Providers>
|
||||
{ENV.IS_LOCAL_DEV ? (
|
||||
<div className="sticky top-0 z-10 flex h-10 place-content-center place-items-center bg-red-500 text-lg text-white">
|
||||
Local test environment
|
||||
</div>
|
||||
) : null}
|
||||
{ENV.IS_PREVIEW ? (
|
||||
<div className="sticky top-0 z-10 flex h-10 place-content-center place-items-center bg-red-500 text-lg text-white">
|
||||
Preview deployment
|
||||
</div>
|
||||
) : null}
|
||||
{children}
|
||||
</Providers>
|
||||
<Analytics />
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user