Skip to content

Commit 79fbda3

Browse files
committed
feat: local and preview detection
1 parent 2848591 commit 79fbda3

File tree

33 files changed

+1069
-1035
lines changed

33 files changed

+1069
-1035
lines changed

.github/workflows/documentation.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ jobs:
7676
for PACKAGE in "${PACKAGES[@]}"; do
7777
cd "packages/${PACKAGE}"
7878
../../main/packages/api-extractor/bin/api-extractor run --local --minify
79+
../../main/packages/scripts/bin/generateSplitDocumentation
7980
cd ../..
8081
done
8182

apps/guide/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@
6565
"sharp": "^0.33.2"
6666
},
6767
"devDependencies": {
68-
"@next/bundle-analyzer": "14.1.0",
68+
"@next/bundle-analyzer": "14.1.1",
6969
"@testing-library/react": "^14.2.1",
7070
"@testing-library/user-event": "^14.5.2",
7171
"@types/html-escaper": "^3.0.2",
7272
"@types/node": "18.18.8",
73-
"@types/react": "^18.2.60",
73+
"@types/react": "^18.2.61",
7474
"@types/react-dom": "^18.2.19",
7575
"@unocss/eslint-plugin": "^0.58.5",
7676
"@unocss/postcss": "^0.58.5",

apps/website/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@
5656
"cmdk": "^0.2.1",
5757
"geist": "^1.2.2",
5858
"jotai": "^2.7.0",
59-
"lucide-react": "^0.343.0",
59+
"lucide-react": "^0.344.0",
6060
"meilisearch": "^0.37.0",
61-
"next": "14.1.1-canary.80",
61+
"next": "14.1.2-canary.2",
6262
"next-mdx-remote": "^4.4.1",
6363
"next-themes": "^0.2.1",
6464
"overlayscrollbars": "^2.5.0",
@@ -71,18 +71,18 @@
7171
"vaul": "^0.9.0"
7272
},
7373
"devDependencies": {
74-
"@next/bundle-analyzer": "14.1.1-canary.80",
74+
"@next/bundle-analyzer": "14.1.2-canary.2",
7575
"@react-aria/optimize-locales-plugin": "^1.0.2",
7676
"@shikijs/rehype": "1.1.7",
7777
"@tailwindcss/typography": "^0.5.10",
7878
"@testing-library/react": "^14.2.1",
7979
"@testing-library/user-event": "^14.5.2",
8080
"@types/node": "18.18.8",
81-
"@types/react": "^18.2.60",
81+
"@types/react": "^18.2.61",
8282
"@types/react-dom": "^18.2.19",
8383
"@vitejs/plugin-react": "^4.2.1",
8484
"@vitest/coverage-v8": "^1.3.1",
85-
"autoprefixer": "^10.4.17",
85+
"autoprefixer": "^10.4.18",
8686
"cpy-cli": "^5.0.0",
8787
"cross-env": "^7.0.3",
8888
"eslint": "^8.57.0",

apps/website/src/app/docs/packages/[packageName]/[version]/[item]/opengraph-image.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/* eslint-disable react/no-unknown-property */
22
import { ImageResponse } from 'next/og';
3+
import { fetchNode } from '~/util/fetchNode';
34
import { resolveKind } from '~/util/resolveNodeKind';
45

56
export const runtime = 'edge';
@@ -16,14 +17,7 @@ export default async function Image({
1617
}: {
1718
readonly params: { readonly item: string; readonly packageName: string; readonly version: string };
1819
}) {
19-
const normalizeItem = params.item.split(encodeURIComponent(':')).join('.').toLowerCase();
20-
21-
const isMainVersion = params.version === 'main';
22-
const fileContent = await fetch(
23-
`${process.env.BLOB_STORAGE_URL}/rewrite/${params.packageName}/${params.version}.${normalizeItem}.api.json`,
24-
{ next: isMainVersion ? { revalidate: 0 } : { revalidate: 604_800 } },
25-
);
26-
const node = await fileContent.json();
20+
const node = await fetchNode({ item: params.item, packageName: params.packageName, version: params.version });
2721

2822
return new ImageResponse(
2923
(

apps/website/src/app/docs/packages/[packageName]/[version]/[item]/page.tsx

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
// import { readFile } from 'node:fs/promises';
2-
// import { join } from 'node:path';
3-
// import { inspect } from 'node:util';
41
import type { Metadata } from 'next';
52
import { DocItem } from '~/components/DocItem';
3+
import { fetchNode } from '~/util/fetchNode';
64

75
export async function generateMetadata({
86
params,
@@ -25,22 +23,7 @@ export default async function Page({
2523
}: {
2624
readonly params: { readonly item: string; readonly packageName: string; readonly version: string };
2725
}) {
28-
const normalizeItem = params.item.split(encodeURIComponent(':')).join('.').toLowerCase();
29-
30-
// const fileContent = await readFile(
31-
// join(process.cwd(), `../../packages/${params.packageName}/docs/split/${params.version}.${normalizeItem}.api.json`),
32-
// 'utf8',
33-
// );
34-
// const node = JSON.parse(fileContent);
35-
36-
const isMainVersion = params.version === 'main';
37-
const fileContent = await fetch(
38-
`${process.env.BLOB_STORAGE_URL}/rewrite/${params.packageName}/${params.version}.${normalizeItem}.api.json`,
39-
{ next: isMainVersion ? { revalidate: 0 } : { revalidate: 604_800 } },
40-
);
41-
const node = await fileContent.json();
42-
43-
// console.log(inspect(node, { depth: 0 }));
26+
const node = await fetchNode({ item: params.item, packageName: params.packageName, version: params.version });
4427

4528
return (
4629
<main className="flex w-full flex-col gap-8 pb-12 md:pb-0">

apps/website/src/app/docs/packages/[packageName]/[version]/layout.tsx

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
1-
// import { readFile } from 'node:fs/promises';
2-
// import { join } from 'node:path';
3-
// import { inspect } from 'node:util';
41
import type { Metadata } from 'next';
52
import dynamic from 'next/dynamic';
63
import type { PropsWithChildren } from 'react';
74
import { Navigation } from '~/components/Navigation';
85
import { OverlayScrollbarsComponent } from '~/components/OverlayScrollbars';
96
import { Drawer } from '~/components/ui/Drawer';
107
import { Footer } from '~/components/ui/Footer';
8+
import { ENV } from '~/util/env';
9+
import { fetchDependencies } from '~/util/fetchDependencies';
1110

1211
// eslint-disable-next-line promise/prefer-await-to-then
1312
const CmdK = dynamic(async () => import('~/components/ui/CmdK').then((mod) => mod.CmdK), { ssr: false });
@@ -29,30 +28,16 @@ export default async function Layout({
2928
params,
3029
children,
3130
}: PropsWithChildren<{ readonly params: { readonly packageName: string; readonly version: string } }>) {
32-
// const fileContent = await readFile(
33-
// join(process.cwd(), `../../packages/${params.packageName}/docs/split/${params.version}.dependencies.api.json`),
34-
// 'utf8',
35-
// );
36-
// const dependencies = JSON.parse(fileContent);
37-
38-
const isMainVersion = params.version === 'main';
39-
const fileContent = await fetch(
40-
`${process.env.BLOB_STORAGE_URL}/rewrite/${params.packageName}/${params.version}.dependencies.api.json`,
41-
{ next: isMainVersion ? { revalidate: 0 } : { revalidate: 604_800 } },
42-
);
43-
const parsedDependencies = await fileContent.json();
44-
const dependencies = Object.entries<string>(parsedDependencies)
45-
.filter(([key]) => key.startsWith('@discordjs/') && !key.includes('api-extractor'))
46-
.map(([key, value]) => `${key.replace('@discordjs/', '').replaceAll('.', '-')}-${value.replaceAll('.', '-')}`);
47-
48-
// console.log(inspect(dependencies, { depth: 0 }));
31+
const dependencies = await fetchDependencies({ packageName: params.packageName, version: params.version });
4932

5033
return (
5134
// eslint-disable-next-line react/no-unknown-property
52-
<div vaul-drawer-wrapper="" className="mx-auto flex max-w-screen-xl flex-col gap-12 p-6 md:flex-row">
53-
<div className="sticky top-6 hidden flex-shrink-0 self-start md:block">
35+
<div vaul-drawer-wrapper="" className="mx-auto flex max-w-screen-2xl flex-col gap-12 p-6 md:flex-row">
36+
<div
37+
className={`sticky hidden flex-shrink-0 self-start md:block ${ENV.IS_LOCAL_DEV || ENV.IS_PREVIEW ? 'top-[64px]' : 'top-6'}`}
38+
>
5439
<OverlayScrollbarsComponent
55-
className="max-h-[calc(100dvh-48px)]"
40+
className={`${ENV.IS_LOCAL_DEV || ENV.IS_PREVIEW ? 'max-h-[calc(100dvh-48px-40px)]' : 'max-h-[calc(100dvh-48px)]'}`}
5641
defer
5742
options={{
5843
overflow: { x: 'hidden' },

apps/website/src/app/docs/packages/[packageName]/[version]/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default async function Page({ params }: { readonly params: { readonly pac
2323
);
2424

2525
return (
26-
<div className="prose prose-neutral mx-auto max-w-screen-lg dark:prose-invert">
26+
<div className="prose prose-neutral mx-auto max-w-screen-xl dark:prose-invert">
2727
<MDXRemote
2828
options={{
2929
mdxOptions: {

apps/website/src/app/layout.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { Metadata, Viewport } from 'next';
55
import type { PropsWithChildren } from 'react';
66
import { LocalizedStringProvider } from 'react-aria-components/i18n';
77
import { DESCRIPTION } from '~/util/constants';
8+
import { ENV } from '~/util/env';
89
import { Providers } from './providers';
910

1011
import '~/styles/main.css';
@@ -80,9 +81,21 @@ export const metadata: Metadata = {
8081
export default async function RootLayout({ children }: PropsWithChildren) {
8182
return (
8283
<html lang="en" className={`${GeistSans.variable} ${GeistMono.variable} antialiased`} suppressHydrationWarning>
83-
<body className="bg-white dark:bg-[#121212]">
84+
<body className="relative bg-white dark:bg-[#121212]">
8485
<LocalizedStringProvider locale="en-US" />
85-
<Providers>{children}</Providers>
86+
<Providers>
87+
{ENV.IS_LOCAL_DEV ? (
88+
<div className="sticky top-0 z-10 flex h-10 place-content-center place-items-center bg-red-500 text-lg text-white">
89+
Local test environment
90+
</div>
91+
) : null}
92+
{ENV.IS_PREVIEW ? (
93+
<div className="sticky top-0 z-10 flex h-10 place-content-center place-items-center bg-red-500 text-lg text-white">
94+
Preview deployment
95+
</div>
96+
) : null}
97+
{children}
98+
</Providers>
8699
<Analytics />
87100
</body>
88101
</html>

apps/website/src/components/Navigation.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { VscGithubInverted } from '@react-icons/all-files/vsc/VscGithubInverted'
22
import { ChevronDown, ChevronUp } from 'lucide-react';
33
import dynamic from 'next/dynamic';
44
import Link from 'next/link';
5+
import { fetchSitemap } from '~/util/fetchSitemap';
56
import { fetchVersions } from '~/util/fetchVersions';
67
import { resolveNodeKind } from './DocKind';
78
import { NavigationItem } from './NavigationItem';
@@ -26,13 +27,7 @@ export async function Navigation({
2627
readonly packageName: string;
2728
readonly version: string;
2829
}) {
29-
const isMainVersion = version === 'main';
30-
const fileContent = await fetch(
31-
`${process.env.BLOB_STORAGE_URL}/rewrite/${packageName}/${version}.sitemap.api.json`,
32-
{ next: isMainVersion ? { revalidate: 0 } : { revalidate: 604_800 } },
33-
);
34-
const node = await fileContent.json();
35-
30+
const node = await fetchSitemap({ packageName, version });
3631
const versions = await fetchVersions(packageName);
3732

3833
const groupedNodes = node.reduce((acc: any, node: any) => {

apps/website/src/middleware.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
import { sql } from '@vercel/postgres';
22
import { NextResponse, type NextRequest } from 'next/server';
33
import { PACKAGES } from './util/constants';
4+
import { ENV } from './util/env';
45

56
async function fetchLatestVersion(packageName: string): Promise<string> {
7+
if (ENV.IS_LOCAL_DEV) {
8+
return 'main';
9+
}
10+
611
const { rows } = await sql`select version from documentation where name = ${packageName} order by version desc`;
712

813
return rows.map((row) => row.version).at(1) ?? 'main';

0 commit comments

Comments
 (0)