add: article view

View for blog articles
This commit is contained in:
webfussel 2025-06-12 14:11:52 +02:00
parent 579491f216
commit 4104477533
15 changed files with 121 additions and 33 deletions

View file

@ -17,11 +17,19 @@ const makeItem = (article: BlogCollectionItem, base: string) => `
</item>
`
const simpleDate = (date: Date) => {
date.setDate(date.getDate() + 1)
return `${date.getFullYear()}-${`${date.getMonth() + 1}`.padStart(2, '0')}-${date.getDate()}`
}
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 articles = await queryCollection(event, 'blog')
.where('date', '<', simpleDate(new Date()))
.order('date', 'DESC')
.all()
const xmlItems = articles.map(article => makeItem(article, blogUrl)).join('')