Update revalidate paths again

This commit is contained in:
Henrik Larsson 2023-07-07 15:56:19 +02:00
parent 4b33503631
commit 1857278dda

View File

@ -1,5 +1,4 @@
import { isValidSignature, SIGNATURE_HEADER_NAME } from '@sanity/webhook'; import { isValidSignature, SIGNATURE_HEADER_NAME } from '@sanity/webhook';
import { i18n } from 'i18n-config';
import { revalidatePath } from 'next/cache'; import { revalidatePath } from 'next/cache';
import { headers } from 'next/headers'; import { headers } from 'next/headers';
import { NextRequest, NextResponse } from 'next/server'; import { NextRequest, NextResponse } from 'next/server';
@ -26,22 +25,15 @@ export async function POST(request: NextRequest) {
return; return;
} }
const slug: string = requestData.slug; const slug = requestData.slug;
const type: string = requestData.type; const type = requestData.type;
const locale: string = requestData.locale;
if (type === 'home') { if (type === 'home') {
revalidatePath(`${slug}`) revalidatePath(`${slug}`)
console.log(`Revalidated path: ${slug}`);
} else { } else {
if (i18n.defaultLocale === locale) { revalidatePath(`${slug}`)
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() }); return NextResponse.json({ revalidated: true, now: Date.now() });
} }