39 lines
No EOL
1.1 KiB
TypeScript
39 lines
No EOL
1.1 KiB
TypeScript
import { BlogCollectionItem } from '@nuxt/content'
|
|
|
|
const clean = (value: string) => value
|
|
.replace(/&/g, '&')
|
|
.replace(/</g, '<')
|
|
.replace(/>/g, '>')
|
|
.replace(/ä/g, 'ä')
|
|
.replace(/ö/g, 'ö')
|
|
.replace(/ü/g, 'ü')
|
|
.replace(/ß/g, 'ß')
|
|
|
|
const makeItem = (article: BlogCollectionItem, base: string) => `
|
|
<item>
|
|
<title>${clean(article.title)}</title>
|
|
<description>${clean(article.description)}</description>
|
|
<link>${base}${article.path}</link>
|
|
</item>
|
|
`
|
|
|
|
export default defineEventHandler(async event => {
|
|
const baseUrl = getRequestURL(event)
|
|
const blogUrl = `${baseUrl.protocol}//${baseUrl.host}`
|
|
|
|
const articles = (await queryCollection(event, 'blog').order('date', 'DESC').all())
|
|
|
|
const xmlItems = articles.map(article => makeItem(article, blogUrl)).join('')
|
|
|
|
return `<?xml version="1.0" encoding="UTF-8"?>
|
|
<rss version="2.0">
|
|
<channel>
|
|
<title>Blogfussel</title>
|
|
<link>${baseUrl}/blog</link>
|
|
<description>für mehr Fussel im Blog</description>
|
|
<language>de</language>
|
|
${xmlItems}
|
|
</channel>
|
|
</rss>
|
|
`
|
|
}) |