diff --git a/app/sitemap.xml/route.ts b/app/sitemap.xml/route.ts new file mode 100644 index 0000000..45acb9d --- /dev/null +++ b/app/sitemap.xml/route.ts @@ -0,0 +1,40 @@ +"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) => ` + + ${baseUrl}/news/detail/${article.id}-${article.slug} + ${new Date(article.updatedAt).toISOString()} + weekly + 0.8 + ` + ) + .join(""); + + const sitemap = ` + + + ${baseUrl} + ${new Date().toISOString()} + daily + 1.0 + + ${urls} + `; + + return new NextResponse(sitemap, { + headers: { + "Content-Type": "application/xml", + }, + }); +}