feat: revalidate-all fetches all articles; add revalidate-all script; fix HOLOSTARS image

This commit is contained in:
achmad
2026-05-29 02:50:25 +07:00
parent a2fba503e3
commit 488ad051fb
2 changed files with 24 additions and 4 deletions
+14 -4
View File
@@ -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
+10
View File
@@ -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 .