fix seo and first page and 404 page
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
import { revalidateTag } from "next/cache";
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
|
||||
/**
|
||||
* پاک کردن کش مقالات وردپرس.
|
||||
* وقتی در وردپرس مقالهای منتشر یا ویرایش شد، این آدرس را با secret فراخوانی کنید
|
||||
* تا کش دانشنامه و مقالهها بدون ریستارت سرور بهروز شود.
|
||||
*
|
||||
* استفاده در وردپرس:
|
||||
* - با پلاگین Webhook یا کد تم: بعد از save_post درخواست به این آدرس بفرست.
|
||||
* - مثال: GET یا POST /api/revalidate?secret=YOUR_REVALIDATE_SECRET
|
||||
* - یا هدر: x-revalidate-secret: YOUR_REVALIDATE_SECRET
|
||||
*/
|
||||
export async function GET(request: NextRequest) {
|
||||
return handleRevalidate(request);
|
||||
}
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
return handleRevalidate(request);
|
||||
}
|
||||
|
||||
async function handleRevalidate(request: NextRequest) {
|
||||
const secret = process.env.REVALIDATE_SECRET;
|
||||
if (!secret) {
|
||||
return NextResponse.json(
|
||||
{ error: "REVALIDATE_SECRET تنظیم نشده است." },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
|
||||
const provided =
|
||||
request.nextUrl.searchParams.get("secret") ??
|
||||
request.headers.get("x-revalidate-secret");
|
||||
if (provided !== secret) {
|
||||
return NextResponse.json({ error: "غیرمجاز" }, { status: 401 });
|
||||
}
|
||||
|
||||
try {
|
||||
revalidateTag("blog-posts");
|
||||
return NextResponse.json({ revalidated: true, now: Date.now() });
|
||||
} catch (err) {
|
||||
return NextResponse.json(
|
||||
{ error: "خطا در پاک کردن کش" },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user