add: category, date sorting
Add category layouts and date sorting
This commit is contained in:
parent
91b59e4ebe
commit
9b66a79a8c
17 changed files with 2495 additions and 17729 deletions
39
server/routes/blog/rss.xml.ts
Normal file
39
server/routes/blog/rss.xml.ts
Normal file
|
@ -0,0 +1,39 @@
|
|||
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>
|
||||
`
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue