export default defineEventHandler(async (event) => { const config = useRuntimeConfig(); const site = config.public.siteUrl || "https://montech.ir"; const apiBase = config.apiBase || "http://127.0.0.1:3050"; let posts: Array<{ slug: string; updatedAt?: string; publishedAt?: string }> = []; try { posts = await $fetch(`${apiBase}/api/public/blog`); } catch { posts = []; } const staticUrls = ["", "/blog", "/gallery"]; const urls = [ ...staticUrls.map((path) => ({ loc: `${site}${path || "/"}`, changefreq: "weekly", priority: path === "" ? "1.0" : "0.8" })), ...posts.map((p) => ({ loc: `${site}/blog/${p.slug}`, changefreq: "monthly", priority: "0.6", lastmod: p.updatedAt || p.publishedAt, })), ]; const body = ` ${urls .map( (u) => ` ${u.loc} ${"lastmod" in u && u.lastmod ? `${new Date(u.lastmod as string).toISOString()}` : ""} ${u.changefreq} ${u.priority} `, ) .join("\n")} `; setHeader(event, "Content-Type", "application/xml"); return body; });