feat: revalidate-all fetches all articles; add revalidate-all script; fix HOLOSTARS image
This commit is contained in:
@@ -21,17 +21,27 @@ export async function POST(req: NextRequest) {
|
|||||||
|
|
||||||
revalidatePath('/')
|
revalidatePath('/')
|
||||||
|
|
||||||
const categories = await directus.request(
|
const [categories, articles] = await Promise.all([
|
||||||
readItems('categories', { fields: ['slug'] })
|
directus.request(readItems('categories', { fields: ['slug'] })) as Promise<{ slug: string }[]>,
|
||||||
) as { 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 = ['/']
|
const paths = ['/']
|
||||||
for (const cat of categories) {
|
for (const cat of categories) {
|
||||||
revalidatePath(`/${cat.slug}`)
|
revalidatePath(`/${cat.slug}`)
|
||||||
paths.push(`/${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
|
const { article_id } = body
|
||||||
|
|||||||
@@ -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 .
|
||||||
Reference in New Issue
Block a user