From acf92d6fc1f694bd056dd66b3c2df47f89914286 Mon Sep 17 00:00:00 2001 From: DrMint Date: Wed, 30 Mar 2022 00:45:04 +0200 Subject: [PATCH] Added content to the list of revalidatable pages --- src/pages/api/revalidate.ts | 38 ++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/src/pages/api/revalidate.ts b/src/pages/api/revalidate.ts index 7cf6391..e26ecb8 100644 --- a/src/pages/api/revalidate.ts +++ b/src/pages/api/revalidate.ts @@ -1,11 +1,13 @@ import type { NextApiRequest, NextApiResponse } from "next"; import getConfig from "next/config"; -export type RequestMailProps = +export type RequestProps = | HookRangedContent | HookPostContent | HookLibraryItem - | HookChronology; + | HookChronology + | HookContent + | HookCustom; export type HookRangedContent = { event: "entry.update" | "entry.delete" | "entry.create"; @@ -20,6 +22,18 @@ export type HookRangedContent = { }; }; +export type HookCustom = { + model: "custom"; + url: string; +}; + +export type HookContent = { + model: "content"; + entry: { + slug: string; + }; +}; + export type HookPostContent = { event: "entry.update" | "entry.delete" | "entry.create"; model: "post"; @@ -51,7 +65,7 @@ export default async function Mail( res: NextApiResponse ) { console.log(req.body); - const body = req.body as RequestMailProps; + const body = req.body as RequestProps; const { serverRuntimeConfig } = getConfig(); // Check for secret to confirm this is a valid request @@ -86,6 +100,16 @@ export default async function Mail( break; } + case "content": { + paths.push(`/contents`); + paths.push(`/contents/${body.entry.slug}`); + serverRuntimeConfig.locales?.map((locale: string) => { + paths.push(`/${locale}/contents/${body.entry.slug}`); + paths.push(`/${locale}/contents`); + }); + break; + } + case "chronology-era": case "chronology-item": { paths.push(`/wiki/chronology`); @@ -108,7 +132,15 @@ export default async function Mail( ); } }); + break; + } + case "custom": { + paths.push(`${body.url}`); + break; + } + + case "content": { break; }