mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-15 02:53:31 +01:00
fix(website): make sure to use proper revalidate and per request caching
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import { readFile } from 'node:fs/promises';
|
import { readFile } from 'node:fs/promises';
|
||||||
import { join } from 'node:path';
|
import { join } from 'node:path';
|
||||||
import { connect } from '@planetscale/database';
|
import { connect } from '@planetscale/database';
|
||||||
|
import { cache } from 'react';
|
||||||
|
|
||||||
const sql = connect({ url: process.env.DATABASE_URL! });
|
const sql = connect({ url: process.env.DATABASE_URL! });
|
||||||
|
|
||||||
@@ -12,7 +13,7 @@ export async function fetchVersions(packageName: string): Promise<string[]> {
|
|||||||
return response.json();
|
return response.json();
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function fetchModelJSON(packageName: string, version: string): Promise<unknown> {
|
export const fetchModelJSON = cache(async (packageName: string, version: string): Promise<unknown> => {
|
||||||
if (process.env.NEXT_PUBLIC_LOCAL_DEV) {
|
if (process.env.NEXT_PUBLIC_LOCAL_DEV) {
|
||||||
const res = await readFile(
|
const res = await readFile(
|
||||||
join(process.cwd(), '..', '..', 'packages', packageName, 'docs', 'docs.api.json'),
|
join(process.cwd(), '..', '..', 'packages', packageName, 'docs', 'docs.api.json'),
|
||||||
@@ -34,4 +35,4 @@ export async function fetchModelJSON(packageName: string, version: string): Prom
|
|||||||
|
|
||||||
// @ts-expect-error: https://github.com/planetscale/database-js/issues/71
|
// @ts-expect-error: https://github.com/planetscale/database-js/issues/71
|
||||||
return rows[0].data;
|
return rows[0].data;
|
||||||
}
|
});
|
||||||
|
|||||||
@@ -84,6 +84,9 @@ function resolveMemberSearchParams(packageName: string, member: ApiItem): URLSea
|
|||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line unicorn/numeric-separators-style
|
||||||
|
export const revalidate = 3600;
|
||||||
|
|
||||||
export async function generateMetadata({ params }: { params: ItemRouteParams }) {
|
export async function generateMetadata({ params }: { params: ItemRouteParams }) {
|
||||||
const member = (await fetchHeadMember(params))!;
|
const member = (await fetchHeadMember(params))!;
|
||||||
const name = `discord.js${member?.displayName ? ` | ${member.displayName}` : ''}`;
|
const name = `discord.js${member?.displayName ? ` | ${member.displayName}` : ''}`;
|
||||||
|
|||||||
@@ -20,6 +20,9 @@ export interface VersionRouteParams {
|
|||||||
version: string;
|
version: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line unicorn/numeric-separators-style
|
||||||
|
export const revalidate = 3600;
|
||||||
|
|
||||||
export async function generateStaticParams() {
|
export async function generateStaticParams() {
|
||||||
const params: VersionRouteParams[] = [];
|
const params: VersionRouteParams[] = [];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user