From 4b33503631107f85f4d9fe8d45bb1eeeb694ff15 Mon Sep 17 00:00:00 2001 From: Henrik Larsson Date: Fri, 7 Jul 2023 15:52:52 +0200 Subject: [PATCH] Update revalidate paths again --- app/api/revalidate/sanity/route.ts | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/app/api/revalidate/sanity/route.ts b/app/api/revalidate/sanity/route.ts index 6e6b80457..d17e1d6f1 100644 --- a/app/api/revalidate/sanity/route.ts +++ b/app/api/revalidate/sanity/route.ts @@ -1,4 +1,5 @@ import { isValidSignature, SIGNATURE_HEADER_NAME } from '@sanity/webhook'; +import { i18n } from 'i18n-config'; import { revalidatePath } from 'next/cache'; import { headers } from 'next/headers'; import { NextRequest, NextResponse } from 'next/server'; @@ -26,9 +27,21 @@ export async function POST(request: NextRequest) { } const slug: string = requestData.slug; + const type: string = requestData.type; + const locale: string = requestData.locale; - revalidatePath(`${slug}`) + if (type === 'home') { + revalidatePath(`${slug}`) + console.log(`Revalidated path: ${slug}`); + } else { + if (i18n.defaultLocale === locale) { + revalidatePath(`${slug}`) + console.log(`Revalidated path: ${slug}`); + } else { + revalidatePath(`${locale}${slug}`) + console.log(`Revalidated path: ${locale}${slug}`); + } + } - console.log(`Revalidated path: ${slug}`); return NextResponse.json({ revalidated: true, now: Date.now() }); } \ No newline at end of file