import { getConfig } from '../utils/config' import { listArticles, listWorks } from '../utils/content' /** * 动态站点地图 /sitemap.xml。 * 内容来自数据库(后台可维护),路由自动跟随。 */ export default defineEventHandler(() => { const { siteUrl } = getConfig() const articles = listArticles({ publishedOnly: true }) const works = listWorks({ publishedOnly: true }) 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 works) { urls.push({ loc: `/work/${item.slug}`, changefreq: 'monthly', priority: '0.7' }) } for (const item of articles) { 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' }, }) })