add: SEO for articles

SEO and SchemaORg for articles
This commit is contained in:
webfussel 2025-06-14 10:23:46 +02:00
parent f1cb4048a4
commit d6859cdaad
22 changed files with 198 additions and 125 deletions

View file

@ -0,0 +1,39 @@
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,
}
})