From 1f01ae3d2b4c2e91ff84708ee164b78a55cdfeb6 Mon Sep 17 00:00:00 2001 From: DrMint Date: Sun, 15 May 2022 13:12:30 +0200 Subject: [PATCH] Fixed the revalidate --- src/components/PostPage.tsx | 2 +- src/pages/api/mail.ts | 2 +- src/pages/api/revalidate.ts | 42 +++++++++++++++++++++++++++++-------- 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/src/components/PostPage.tsx b/src/components/PostPage.tsx index e324f0a..5402d58 100644 --- a/src/components/PostPage.tsx +++ b/src/components/PostPage.tsx @@ -50,7 +50,7 @@ export function PostPage(props: Immutable): JSX.Element { const [selectedTranslation, LanguageSwitcher] = useSmartLanguage({ items: post.translations, languages: languages, - languageExtractor: (item) => item?.language?.data?.attributes?.code, + languageExtractor: (item) => item.language?.data?.attributes?.code, }); const thumbnail = diff --git a/src/pages/api/mail.ts b/src/pages/api/mail.ts index 7fb6b00..e874acb 100644 --- a/src/pages/api/mail.ts +++ b/src/pages/api/mail.ts @@ -14,7 +14,7 @@ export interface RequestMailProps { formName: string; } -export async function Mail( +export default async function Mail( req: NextApiRequest, res: NextApiResponse ) { diff --git a/src/pages/api/revalidate.ts b/src/pages/api/revalidate.ts index 99673cb..1f0a0fc 100644 --- a/src/pages/api/revalidate.ts +++ b/src/pages/api/revalidate.ts @@ -7,6 +7,7 @@ type RequestProps = | HookLibraryItem | HookChronology | HookContent + | HookContentGroup | HookCustom; type HookRangedContent = { @@ -60,6 +61,16 @@ type HookLibraryItem = { }; }; +type HookContentGroup = { + event: "entry.update" | "entry.delete" | "entry.create"; + model: "contents-group"; + entry: { + contents: { + slug: string; + }[]; + }; +}; + type HookChronology = { event: "entry.update" | "entry.delete" | "entry.create"; model: "chronology-era" | "chronology-item"; @@ -70,7 +81,7 @@ type ResponseMailProps = { revalidated: boolean; }; -export async function Mail( +export default async function Revalidate( req: NextApiRequest, res: NextApiResponse ) { @@ -93,8 +104,8 @@ export async function Mail( paths.push(`/news`); paths.push(`/news/${body.entry.slug}`); serverRuntimeConfig.locales?.map((locale: string) => { - paths.push(`/${locale}/news/${body.entry.slug}`); paths.push(`/${locale}/news`); + paths.push(`/${locale}/news/${body.entry.slug}`); }); break; } @@ -103,24 +114,26 @@ export async function Mail( paths.push(`/library`); paths.push(`/library/${body.entry.slug}`); paths.push(`/library/${body.entry.slug}/scans`); + body.entry.subitem_of.map((parentItem) => { + paths.push(`/library/${parentItem.slug}`); + }); serverRuntimeConfig.locales?.map((locale: string) => { + paths.push(`/${locale}/library`); paths.push(`/${locale}/library/${body.entry.slug}`); paths.push(`/${locale}/library/${body.entry.slug}/scans`); body.entry.subitem_of.map((parentItem) => { paths.push(`/${locale}/library/${parentItem.slug}`); }); - paths.push(`/${locale}/library`); }); break; } case "content": { - console.log(body.entry.ranged_contents); 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`); + paths.push(`/${locale}/contents/${body.entry.slug}`); }); if (body.entry.ranged_contents.length > 0) { body.entry.ranged_contents.map((ranged_content) => { @@ -164,16 +177,27 @@ export async function Mail( break; } + case "contents-group": { + paths.push(`/contents`); + serverRuntimeConfig.locales?.map((locale: string) => { + paths.push(`/${locale}/contents`); + }); + body.entry.contents.map((content) => { + paths.push(`/contents/${content.slug}`); + serverRuntimeConfig.locales?.map((locale: string) => { + paths.push(`/${locale}/contents/${content.slug}`); + }); + }); + break; + } + case "custom": { paths.push(`${body.url}`); break; } - case "content": { - break; - } - default: + console.log(body); break; }