- Introduced a new script `make-blog-cover.mjs` to create a default cover image for blog posts. - The image is generated in PNG format with dimensions 1200x630, suitable for Open Graph. - Utilizes the site's branding colors and logo from `public/nobat724.svg`. - Includes custom font styling using the Vazirmatn font. - The generated image is saved to `public/assets/images/blog-default-cover.png`.
34 lines
1.3 KiB
JavaScript
34 lines
1.3 KiB
JavaScript
import { NextResponse } from "next/server";
|
|
import { revalidateTag, revalidatePath } from "next/cache";
|
|
|
|
/**
|
|
* باطلسازی on-demand کش ISR بلاگ.
|
|
*
|
|
* `clinicpro` (App\Blog\Service\BlogCacheInvalidator) بعد از هر
|
|
* create/update/delete/review این مسیر را صدا میزند تا تغییر پنل ادمین بدون
|
|
* انتظار یکساعتهٔ `revalidate: 3600` روی سایت بیاید.
|
|
*
|
|
* قرارداد: POST { tags: string[] } با هدر `X-Revalidate-Secret`.
|
|
*/
|
|
export async function POST(request) {
|
|
const secret = process.env.REVALIDATE_SECRET;
|
|
if (!secret || request.headers.get("x-revalidate-secret") !== secret) {
|
|
return NextResponse.json({ revalidated: false }, { status: 401 });
|
|
}
|
|
|
|
const body = await request.json().catch(() => null);
|
|
const tags = body?.tags;
|
|
if (!Array.isArray(tags) || tags.length === 0) {
|
|
return NextResponse.json(
|
|
{ revalidated: false, error: "tags required" },
|
|
{ status: 400 }
|
|
);
|
|
}
|
|
|
|
tags.forEach((tag) => revalidateTag(String(tag)));
|
|
// فهرست مقالات صفحهٔ خودش را با tag نمیگیرد، پس مسیرش جدا باطل میشود.
|
|
if (tags.includes("blog-list")) revalidatePath("/blogs");
|
|
|
|
return NextResponse.json({ revalidated: true, tags });
|
|
}
|