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