39 lines
No EOL
1.1 KiB
TypeScript
39 lines
No EOL
1.1 KiB
TypeScript
import { BlogCollectionItem } from '@nuxt/content'
|
|
|
|
|
|
const simpleDate = (date: Date) => {
|
|
date.setDate(date.getDate() + 1)
|
|
return `${date.getFullYear()}-${`${date.getMonth() + 1}`.padStart(2, '0')}-${date.getDate()}`
|
|
}
|
|
|
|
const author = (baseUrl: string) => ({
|
|
name: 'webfussel',
|
|
img: `${baseUrl}/img/blog/authors/webfussel@3x.webp`,
|
|
img1x: `${baseUrl}/img/blog/authors/webfussel@1x.webp`,
|
|
img2x: `${baseUrl}/img/blog/authors/webfussel@2x.webp`,
|
|
img3x: `${baseUrl}/img/blog/authors/webfussel@3x.webp`,
|
|
})
|
|
|
|
export default defineEventHandler(async event => {
|
|
const url = getRequestURL(event)
|
|
const baseUrl = `${url.protocol}//${url.host}`
|
|
|
|
const articles = await queryCollection(event, 'blog')
|
|
.where('date', '<', simpleDate(new Date()))
|
|
.order('date', 'DESC')
|
|
.all()
|
|
|
|
const entries = articles.map(article => ({
|
|
url: `${baseUrl}${article.path}`,
|
|
title: article.title,
|
|
excerpt: article.description,
|
|
date: article.date,
|
|
thumbnail: `${baseUrl}${article.thumbnail}`,
|
|
category: article.category,
|
|
}))
|
|
|
|
return {
|
|
author: author(baseUrl),
|
|
posts: entries,
|
|
}
|
|
}) |