import type {APIRoute} from 'astro'; import {metadata} from "@/consts"; import {createHttp} from "@/lib/request.ts"; import type {PostForSitemap} from "@/types"; import dayjs from "dayjs"; const site = metadata.site export const GET: APIRoute = async (context) => { const http = createHttp(context.request.headers); const {data} = await http.get>("posts/sitemap") const urls = data .filter((url, index, array) => { return array.indexOf(url) === index; }); const xml = ` ${urls.map((post) => ` ${site}/${post.slug} ${dayjs(post.updated_at || post.created_at).toISOString()} ` ) .join('\n')} `; return new Response(xml, { status: 200, headers: { 'Content-Type': 'application/xml; charset=utf-8', 'Cache-Control': 'public, max-age=3600, s-maxage=3600', }, }); };