feat:sitemap
This commit is contained in:
parent
6bd881fe2e
commit
7544902d59
|
|
@ -0,0 +1,43 @@
|
|||
import { getListArticle } from "@/services/article";
|
||||
import { convertDateFormatNoTimeV2 } from "@/utils/global";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export async function GET() {
|
||||
const baseUrl = "https://eppid.polri.go.id";
|
||||
|
||||
const request = { limit: "100", page: 0, search: "" };
|
||||
const response = await getListArticle(request);
|
||||
|
||||
const articles = response?.data?.data || [];
|
||||
|
||||
const urls = articles
|
||||
.map(
|
||||
(article: any) => `
|
||||
<url>
|
||||
<loc>${baseUrl}/news/detail/${article.id}</loc>
|
||||
<lastmod>${convertDateFormatNoTimeV2(
|
||||
new Date(article.updatedAt)
|
||||
)}</lastmod>
|
||||
<changefreq>weekly</changefreq>
|
||||
<priority>0.8</priority>
|
||||
</url>`
|
||||
)
|
||||
.join("");
|
||||
|
||||
const sitemap = `<?xml version="1.0" encoding="UTF-8"?>
|
||||
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
|
||||
<url>
|
||||
<loc>${baseUrl}</loc>
|
||||
<lastmod>${convertDateFormatNoTimeV2(new Date())}</lastmod>
|
||||
<changefreq>daily</changefreq>
|
||||
<priority>1.0</priority>
|
||||
</url>
|
||||
${urls}
|
||||
</urlset>`;
|
||||
|
||||
return new NextResponse(sitemap, {
|
||||
headers: {
|
||||
"Content-Type": "application/xml",
|
||||
},
|
||||
});
|
||||
}
|
||||
Loading…
Reference in New Issue