Added content to the list of revalidatable pages

This commit is contained in:
DrMint 2022-03-30 00:45:04 +02:00
parent 324eb7c366
commit acf92d6fc1
1 changed files with 35 additions and 3 deletions

View File

@ -1,11 +1,13 @@
import type { NextApiRequest, NextApiResponse } from "next"; import type { NextApiRequest, NextApiResponse } from "next";
import getConfig from "next/config"; import getConfig from "next/config";
export type RequestMailProps = export type RequestProps =
| HookRangedContent | HookRangedContent
| HookPostContent | HookPostContent
| HookLibraryItem | HookLibraryItem
| HookChronology; | HookChronology
| HookContent
| HookCustom;
export type HookRangedContent = { export type HookRangedContent = {
event: "entry.update" | "entry.delete" | "entry.create"; 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 = { export type HookPostContent = {
event: "entry.update" | "entry.delete" | "entry.create"; event: "entry.update" | "entry.delete" | "entry.create";
model: "post"; model: "post";
@ -51,7 +65,7 @@ export default async function Mail(
res: NextApiResponse<ResponseMailProps> res: NextApiResponse<ResponseMailProps>
) { ) {
console.log(req.body); console.log(req.body);
const body = req.body as RequestMailProps; const body = req.body as RequestProps;
const { serverRuntimeConfig } = getConfig(); const { serverRuntimeConfig } = getConfig();
// Check for secret to confirm this is a valid request // Check for secret to confirm this is a valid request
@ -86,6 +100,16 @@ export default async function Mail(
break; 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-era":
case "chronology-item": { case "chronology-item": {
paths.push(`/wiki/chronology`); paths.push(`/wiki/chronology`);
@ -108,7 +132,15 @@ export default async function Mail(
); );
} }
}); });
break;
}
case "custom": {
paths.push(`${body.url}`);
break;
}
case "content": {
break; break;
} }