add: article view
View for blog articles
This commit is contained in:
parent
579491f216
commit
4104477533
15 changed files with 121 additions and 33 deletions
|
@ -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('')
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue