mirror of
https://github.com/discordjs/discord.js.git
synced 2024-08-21 16:54:53 +12:00
fix: prerender bailout
This commit is contained in:
parent
7f467ed2d1
commit
a35d760421
4 changed files with 38 additions and 49 deletions
|
@ -1,4 +1,5 @@
|
||||||
import type { Metadata } from 'next';
|
import type { Metadata } from 'next';
|
||||||
|
import { notFound } from 'next/navigation';
|
||||||
import { DocItem } from '~/components/DocItem';
|
import { DocItem } from '~/components/DocItem';
|
||||||
import { fetchNode } from '~/util/fetchNode';
|
import { fetchNode } from '~/util/fetchNode';
|
||||||
|
|
||||||
|
@ -25,6 +26,10 @@ export default async function Page({
|
||||||
}) {
|
}) {
|
||||||
const node = await fetchNode({ item: params.item, packageName: params.packageName, version: params.version });
|
const node = await fetchNode({ item: params.item, packageName: params.packageName, version: params.version });
|
||||||
|
|
||||||
|
if (!node) {
|
||||||
|
notFound();
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<main className="flex w-full flex-col gap-8 pb-12 md:pb-0">
|
<main className="flex w-full flex-col gap-8 pb-12 md:pb-0">
|
||||||
<DocItem node={node} packageName={params.packageName} version={params.version} />
|
<DocItem node={node} packageName={params.packageName} version={params.version} />
|
||||||
|
|
|
@ -2,6 +2,7 @@ import { VscGithubInverted } from '@react-icons/all-files/vsc/VscGithubInverted'
|
||||||
import { ChevronDown, ChevronUp } from 'lucide-react';
|
import { ChevronDown, ChevronUp } from 'lucide-react';
|
||||||
import dynamic from 'next/dynamic';
|
import dynamic from 'next/dynamic';
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
|
import { notFound } from 'next/navigation';
|
||||||
import { fetchSitemap } from '~/util/fetchSitemap';
|
import { fetchSitemap } from '~/util/fetchSitemap';
|
||||||
import { fetchVersions } from '~/util/fetchVersions';
|
import { fetchVersions } from '~/util/fetchVersions';
|
||||||
import { resolveNodeKind } from './DocKind';
|
import { resolveNodeKind } from './DocKind';
|
||||||
|
@ -28,6 +29,11 @@ export async function Navigation({
|
||||||
readonly version: string;
|
readonly version: string;
|
||||||
}) {
|
}) {
|
||||||
const node = await fetchSitemap({ packageName, version });
|
const node = await fetchSitemap({ packageName, version });
|
||||||
|
|
||||||
|
if (!node) {
|
||||||
|
notFound();
|
||||||
|
}
|
||||||
|
|
||||||
const versions = await fetchVersions(packageName);
|
const versions = await fetchVersions(packageName);
|
||||||
|
|
||||||
const groupedNodes = node.reduce((acc: any, node: any) => {
|
const groupedNodes = node.reduce((acc: any, node: any) => {
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import { readFile } from 'node:fs/promises';
|
import { readFile } from 'node:fs/promises';
|
||||||
import { join } from 'node:path';
|
import { join } from 'node:path';
|
||||||
import { notFound } from 'next/navigation';
|
|
||||||
import { ENV } from './env';
|
import { ENV } from './env';
|
||||||
|
|
||||||
export async function fetchNode({
|
export async function fetchNode({
|
||||||
|
@ -15,32 +14,22 @@ export async function fetchNode({
|
||||||
const normalizeItem = item.split(encodeURIComponent(':')).join('.').toLowerCase();
|
const normalizeItem = item.split(encodeURIComponent(':')).join('.').toLowerCase();
|
||||||
|
|
||||||
if (ENV.IS_LOCAL_DEV) {
|
if (ENV.IS_LOCAL_DEV) {
|
||||||
try {
|
const fileContent = await readFile(
|
||||||
const fileContent = await readFile(
|
join(
|
||||||
join(
|
process.cwd(),
|
||||||
process.cwd(),
|
`../../packages/${packageName}/docs/${packageName}/split/${version}.${normalizeItem}.api.json`,
|
||||||
`../../packages/${packageName}/docs/${packageName}/split/${version}.${normalizeItem}.api.json`,
|
),
|
||||||
),
|
'utf8',
|
||||||
'utf8',
|
|
||||||
);
|
|
||||||
|
|
||||||
return JSON.parse(fileContent);
|
|
||||||
} catch (error_) {
|
|
||||||
console.error(error_);
|
|
||||||
notFound();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const isMainVersion = version === 'main';
|
|
||||||
const fileContent = await fetch(
|
|
||||||
`${process.env.BLOB_STORAGE_URL}/rewrite/${packageName}/${version}.${normalizeItem}.api.json`,
|
|
||||||
{ next: isMainVersion ? { revalidate: 0 } : { revalidate: 604_800 } },
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return await fileContent.json();
|
return JSON.parse(fileContent);
|
||||||
} catch (error_) {
|
|
||||||
console.error(error_);
|
|
||||||
notFound();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isMainVersion = version === 'main';
|
||||||
|
const fileContent = await fetch(
|
||||||
|
`${process.env.BLOB_STORAGE_URL}/rewrite/${packageName}/${version}.${normalizeItem}.api.json`,
|
||||||
|
{ next: isMainVersion ? { revalidate: 0 } : { revalidate: 604_800 } },
|
||||||
|
);
|
||||||
|
|
||||||
|
return fileContent.json();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import { readFile } from 'node:fs/promises';
|
import { readFile } from 'node:fs/promises';
|
||||||
import { join } from 'node:path';
|
import { join } from 'node:path';
|
||||||
import { notFound } from 'next/navigation';
|
|
||||||
import { ENV } from './env';
|
import { ENV } from './env';
|
||||||
|
|
||||||
export async function fetchSitemap({
|
export async function fetchSitemap({
|
||||||
|
@ -11,29 +10,19 @@ export async function fetchSitemap({
|
||||||
readonly version: string;
|
readonly version: string;
|
||||||
}) {
|
}) {
|
||||||
if (ENV.IS_LOCAL_DEV) {
|
if (ENV.IS_LOCAL_DEV) {
|
||||||
try {
|
const fileContent = await readFile(
|
||||||
const fileContent = await readFile(
|
join(process.cwd(), `../../packages/${packageName}/docs/${packageName}/split/${version}.sitemap.api.json`),
|
||||||
join(process.cwd(), `../../packages/${packageName}/docs/${packageName}/split/${version}.sitemap.api.json`),
|
'utf8',
|
||||||
'utf8',
|
|
||||||
);
|
|
||||||
|
|
||||||
return JSON.parse(fileContent);
|
|
||||||
} catch (error_) {
|
|
||||||
console.error(error_);
|
|
||||||
notFound();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
const isMainVersion = version === 'main';
|
|
||||||
const fileContent = await fetch(
|
|
||||||
`${process.env.BLOB_STORAGE_URL}/rewrite/${packageName}/${version}.sitemap.api.json`,
|
|
||||||
{ next: isMainVersion ? { revalidate: 0 } : { revalidate: 604_800 } },
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return await fileContent.json();
|
return JSON.parse(fileContent);
|
||||||
} catch (error_) {
|
|
||||||
console.error(error_);
|
|
||||||
notFound();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const isMainVersion = version === 'main';
|
||||||
|
const fileContent = await fetch(
|
||||||
|
`${process.env.BLOB_STORAGE_URL}/rewrite/${packageName}/${version}.sitemap.api.json`,
|
||||||
|
{ next: isMainVersion ? { revalidate: 0 } : { revalidate: 604_800 } },
|
||||||
|
);
|
||||||
|
|
||||||
|
return fileContent.json();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue