41 lines
1.1 KiB
TypeScript
41 lines
1.1 KiB
TypeScript
|
|
"use server";
|
||
|
|
import { getListArticle } from "@/services/article";
|
||
|
|
import { NextResponse } from "next/server";
|
||
|
|
|
||
|
|
export async function GET() {
|
||
|
|
const baseUrl = "https://humas.polri.go.id";
|
||
|
|
|
||
|
|
const response = await getListArticle({ page: 1, limit: "100", search: "" });
|
||
|
|
|
||
|
|
const articles = response?.data?.data || [];
|
||
|
|
|
||
|
|
const urls = articles
|
||
|
|
.map(
|
||
|
|
(article: any) => `
|
||
|
|
<url>
|
||
|
|
<loc>${baseUrl}/news/detail/${article.id}-${article.slug}</loc>
|
||
|
|
<lastmod>${new Date(article.updatedAt).toISOString()}</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>${new Date().toISOString()}</lastmod>
|
||
|
|
<changefreq>daily</changefreq>
|
||
|
|
<priority>1.0</priority>
|
||
|
|
</url>
|
||
|
|
${urls}
|
||
|
|
</urlset>`;
|
||
|
|
|
||
|
|
return new NextResponse(sitemap, {
|
||
|
|
headers: {
|
||
|
|
"Content-Type": "application/xml",
|
||
|
|
},
|
||
|
|
});
|
||
|
|
}
|