From 488ad051fb32c9513284c5bc1c40c2c9b7652d31 Mon Sep 17 00:00:00 2001 From: achmad Date: Fri, 29 May 2026 02:50:25 +0700 Subject: [PATCH] feat: revalidate-all fetches all articles; add revalidate-all script; fix HOLOSTARS image --- app/api/revalidate/route.ts | 18 ++++++++++++++---- scripts/revalidate-all.sh | 10 ++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 scripts/revalidate-all.sh diff --git a/app/api/revalidate/route.ts b/app/api/revalidate/route.ts index cbd2268..3a13826 100644 --- a/app/api/revalidate/route.ts +++ b/app/api/revalidate/route.ts @@ -21,17 +21,27 @@ export async function POST(req: NextRequest) { revalidatePath('/') - const categories = await directus.request( - readItems('categories', { fields: ['slug'] }) - ) as { slug: string }[] + const [categories, articles] = await Promise.all([ + directus.request(readItems('categories', { fields: ['slug'] })) as Promise<{ slug: string }[]>, + directus.request(readItems('articles', { + fields: ['slug', 'category.slug'], + filter: { status: { _eq: 'published' } }, + limit: 500, + })) as Promise<{ slug: string; category: { slug: string } }[]>, + ]) const paths = ['/'] for (const cat of categories) { revalidatePath(`/${cat.slug}`) paths.push(`/${cat.slug}`) } + for (const article of articles) { + const p = `/${article.category.slug}/${article.slug}` + revalidatePath(p) + paths.push(p) + } - return NextResponse.json({ revalidated: true, paths }) + return NextResponse.json({ revalidated: true, paths: paths.slice(0, 20), total: paths.length }) } const { article_id } = body diff --git a/scripts/revalidate-all.sh b/scripts/revalidate-all.sh new file mode 100644 index 0000000..0971311 --- /dev/null +++ b/scripts/revalidate-all.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +set -euo pipefail + +URL="${1:-https://kotobane.achmad.dev}" +SECRET="${REVALIDATE_SECRET:-1964edNGrm1xqE2oznfeahdheP7oAfwAob4fIxe1Gzo}" + +echo "==> Revalidating all pages (homepage + categories + articles) on $URL ..." +curl -s -X POST "$URL/api/revalidate" \ + -H "Content-Type: application/json" \ + -d "{\"secret\":\"$SECRET\",\"type\":\"all\"}" | jq .