From f59f80d74b7d34e942e03c3d84f9b413c9b9ebb6 Mon Sep 17 00:00:00 2001 From: Rama Priyanto Date: Wed, 20 Aug 2025 09:44:35 +0700 Subject: [PATCH] feat:sitemap --- app/sitemap.xml/route.ts | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 app/sitemap.xml/route.ts 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", + }, + }); +}