import { readSiteDocument } from '../utils/db' const escapeXml = (value: string) => value.replace(/[<>&'\"]/g, character => ({ '<': '<', '>': '>', '&': '&', "'": ''', '"': '"' })[character]!) export default defineEventHandler((event) => { const baseUrl = String(useRuntimeConfig().public.siteUrl).replace(/\/$/, '') const { data, publishedAt } = readSiteDocument('published') const paths = ['/', '/luhui', '/products', '/news', '/statements', '/team', '/privacy', '/terms'] data.products.filter(item => item.status === 'published').forEach(item => paths.push(`/products/${item.slug}`)) data.articles.filter(item => item.status === 'published').forEach(item => paths.push(`/${item.type === 'statement' ? 'statements' : 'news'}/${item.slug}`)) setHeader(event, 'Content-Type', 'application/xml; charset=utf-8') setHeader(event, 'Cache-Control', 'public, max-age=300, stale-while-revalidate=600') return `\n\n${paths.map(path => ` ${escapeXml(`${baseUrl}${path}`)}${escapeXml(publishedAt.slice(0, 10))}`).join('\n')}\n` })