65 lines
1.6 KiB
TypeScript
65 lines
1.6 KiB
TypeScript
"use server";
|
|
import { getListContent } from "@/service/landing/landing";
|
|
import { NextResponse } from "next/server";
|
|
|
|
export async function GET() {
|
|
try {
|
|
const baseUrl = "https://new.netidhub.com/in";
|
|
|
|
const response = await getListContent({
|
|
page: 1,
|
|
limit: "100",
|
|
search: "",
|
|
});
|
|
const articles = response?.data?.data || [];
|
|
|
|
const urls = articles
|
|
.map((article: any) => {
|
|
const type =
|
|
article.fileTypeId == 1
|
|
? "image"
|
|
: article.fileTypeId == 2
|
|
? "video"
|
|
: article.fileTypeId == 3
|
|
? "document"
|
|
: "audio";
|
|
|
|
const slug = article.slug
|
|
? encodeURIComponent(article.slug)
|
|
: article.id;
|
|
const lastmod = article.updatedAt
|
|
? new Date(article.updatedAt).toISOString()
|
|
: new Date().toISOString();
|
|
|
|
return `
|
|
<url>
|
|
<loc>${baseUrl}/${type}/detail/${article.id}-${slug}</loc>
|
|
<lastmod>${lastmod}</lastmod>
|
|
<changefreq>weekly</changefreq>
|
|
<priority>0.8</priority>
|
|
</url>`;
|
|
})
|
|
.join("\n");
|
|
|
|
const sitemap = `<?xml version="1.0" encoding="UTF-8"?>
|
|
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
|
<url>
|
|
<loc>${baseUrl}</loc>
|
|
<lastmod>${new Date().toISOString()}</lastmod>
|
|
<changefreq>daily</changefreq>
|
|
<priority>1.0</priority>
|
|
</url>
|
|
${urls}
|
|
</urlset>`;
|
|
|
|
return new NextResponse(sitemap, {
|
|
headers: {
|
|
"Content-Type": "application/xml",
|
|
},
|
|
});
|
|
} catch (error: any) {
|
|
console.error("Sitemap error:", error);
|
|
return new NextResponse("Sitemap generation failed", { status: 500 });
|
|
}
|
|
}
|