import { getConfig } from '../utils/config' import { newsItems } from '../../app/data/news' import { workItems } from '../../app/data/work' /** * 动态站点地图 /sitemap.xml。 * 路由与数据均来自单一事实源(app/data/*),内容更新无需手工同步。 */ export default defineEventHandler(() => { const { siteUrl } = getConfig() const urls: Array<{ loc: string; changefreq: string; priority: string }> = [ { loc: '/', changefreq: 'weekly', priority: '1.0' }, { loc: '/studio', changefreq: 'monthly', priority: '0.8' }, { loc: '/work', changefreq: 'weekly', priority: '0.8' }, { loc: '/news', changefreq: 'weekly', priority: '0.8' }, { loc: '/tools', changefreq: 'monthly', priority: '0.6' }, { loc: '/contact', changefreq: 'monthly', priority: '0.6' }, ] for (const item of workItems) { urls.push({ loc: `/work/${item.slug}`, changefreq: 'monthly', priority: '0.7' }) } for (const item of newsItems) { urls.push({ loc: `/news/${item.slug}`, changefreq: 'weekly', priority: '0.7' }) } const xml = ` ${urls .map( (u) => ` ${siteUrl}${u.loc} ${u.changefreq} ${u.priority} `, ) .join('\n')} ` return new Response(xml, { headers: { 'Content-Type': 'text/xml; charset=utf-8' }, }) })