fix: revalidate on page level instead

This commit is contained in:
iCrawl
2022-12-02 11:31:59 +01:00
parent 52f56d3c2e
commit 4e4cbb3418
8 changed files with 230 additions and 229 deletions

View File

@@ -56,8 +56,8 @@
"@types/react": "^18.0.25",
"@types/react-dom": "^18.0.9",
"@types/react-syntax-highlighter": "^15.5.5",
"@unocss/cli": "^0.47.4",
"@unocss/reset": "^0.47.4",
"@unocss/cli": "^0.47.5",
"@unocss/reset": "^0.47.5",
"@vitejs/plugin-react": "^2.2.0",
"@vitest/coverage-c8": "^0.25.3",
"astro": "^1.6.12",
@@ -79,7 +79,7 @@
"sharp": "^0.31.2",
"shiki": "^0.11.1",
"typescript": "^4.9.3",
"unocss": "^0.47.4",
"unocss": "^0.47.5",
"vercel": "^28.7.0",
"vitest": "^0.25.3"
},

View File

@@ -54,7 +54,7 @@
"ariakit": "^2.0.0-next.41",
"cmdk": "^0.1.20",
"meilisearch": "^0.30.0",
"next": "^13.0.6-canary.3",
"next": "^13.0.6",
"next-mdx-remote": "^4.2.0",
"next-themes": "npm:@wits/next-themes@latest",
"react": "^18.2.0",
@@ -72,15 +72,15 @@
"swr": "^1.3.0"
},
"devDependencies": {
"@next/bundle-analyzer": "^13.0.5",
"@next/bundle-analyzer": "^13.0.6",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^14.4.3",
"@types/node": "16.18.4",
"@types/react": "^18.0.25",
"@types/react-dom": "^18.0.9",
"@types/react-syntax-highlighter": "^15.5.5",
"@unocss/cli": "^0.47.4",
"@unocss/reset": "^0.47.4",
"@unocss/cli": "^0.47.5",
"@unocss/reset": "^0.47.5",
"@vitejs/plugin-react": "^2.2.0",
"@vitest/coverage-c8": "^0.25.3",
"concurrently": "^7.6.0",
@@ -93,7 +93,7 @@
"prettier": "^2.8.0",
"prettier-plugin-tailwindcss": "^0.2.0",
"typescript": "^4.9.3",
"unocss": "^0.47.4",
"unocss": "^0.47.5",
"vercel": "^28.7.0",
"vitest": "^0.25.3"
},

View File

@@ -44,6 +44,9 @@ import { DESCRIPTION, PACKAGES } from '~/util/constants';
import { findMember, findMemberByKey } from '~/util/model.server';
import { tryResolveDescription } from '~/util/summary';
// eslint-disable-next-line unicorn/numeric-separators-style
export const revalidate = 3600;
export async function generateStaticParams({ params }: { params?: { package: string } }) {
const packageName = params?.package ?? 'builders';
@@ -54,16 +57,12 @@ export async function generateStaticParams({ params }: { params?: { package: str
const res = await readFile(join(cwd(), '..', '..', 'packages', packageName, 'docs', 'docs.api.json'), 'utf8');
data = JSON.parse(res);
} else {
const response = await fetch(`https://docs.discordjs.dev/api/info?package=${packageName}`, {
next: { revalidate: 3_600 },
});
const response = await fetch(`https://docs.discordjs.dev/api/info?package=${packageName}`);
versions = await response.json();
versions = versions.slice(-2);
for (const version of versions) {
const res = await fetch(`https://docs.discordjs.dev/docs/${packageName}/${version}.api.json`, {
next: { revalidate: 3_600 },
});
const res = await fetch(`https://docs.discordjs.dev/docs/${packageName}/${version}.api.json`);
data = [...data, await res.json()];
}
}
@@ -123,9 +122,7 @@ async function getData(packageName: string, slug: string[]) {
const res = await readFile(join(cwd(), '..', '..', 'packages', packageName, 'docs', 'docs.api.json'), 'utf8');
data = JSON.parse(res);
} else {
const res = await fetch(`https://docs.discordjs.dev/docs/${packageName}/${branchName}.api.json`, {
next: { revalidate: 3_600 },
});
const res = await fetch(`https://docs.discordjs.dev/docs/${packageName}/${branchName}.api.json`);
data = await res.json();
}
} catch {

View File

@@ -5,12 +5,15 @@ import Link from 'next/link';
import { notFound } from 'next/navigation';
import { PACKAGES } from '~/util/constants';
// eslint-disable-next-line unicorn/numeric-separators-style
export const revalidate = 3600;
async function getData(pkg: string) {
if (!PACKAGES.includes(pkg)) {
notFound();
}
const res = await fetch(`https://docs.discordjs.dev/api/info?package=${pkg}`, { next: { revalidate: 3_600 } });
const res = await fetch(`https://docs.discordjs.dev/api/info?package=${pkg}`);
const data: string[] = await res.json();
if (!data.length) {

View File

@@ -5,12 +5,13 @@ import { VscPackage } from '@react-icons/all-files/vsc/VscPackage';
import Link from 'next/link';
import { PACKAGES } from '~/util/constants';
// eslint-disable-next-line unicorn/numeric-separators-style
export const revalidate = 3600;
async function getData() {
return Promise.all(
PACKAGES.map(async (pkg) => {
const response = await fetch(`https://docs.discordjs.dev/api/info?package=${pkg}`, {
next: { revalidate: 3_600 },
});
const response = await fetch(`https://docs.discordjs.dev/api/info?package=${pkg}`);
const versions = await response.json();
const latestVersion = versions.at(-2) ?? 'main';
return { packageName: pkg, version: latestVersion };