test: twitter og error

This commit is contained in:
radishzzz 2025-03-16 18:54:08 +00:00
parent b24d5ba9f5
commit 1cb5e6aafc
8 changed files with 4 additions and 7 deletions

View file

@ -0,0 +1,51 @@
import { generateDescription } from '@/utils/description'
import { OGImageRoute } from 'astro-og-canvas'
import { getCollection } from 'astro:content'
// eslint-disable-next-line antfu/no-top-level-await
const blogEntries = await getCollection('posts')
// Convert to page data objects
const pages = Object.fromEntries(
blogEntries.map(post => [
post.slug,
{
title: post.data.title,
description: post.data.description || generateDescription(post),
},
]),
)
// Configure Open Graph image generation route
export const { getStaticPaths, GET } = OGImageRoute({
param: 'image',
pages,
getImageOptions: (_path, page) => ({
title: page.title,
description: page.description,
logo: {
path: './public/image/og-logo.png', // Required local path and PNG format
size: [70],
},
font: {
title: {
families: ['Noto Sans SC'], // or Noto Serif SC
weight: 'Bold',
color: [34, 33, 36],
lineHeight: 1.5,
},
description: {
families: ['Noto Sans SC'], // or Noto Serif SC
color: [72, 71, 74],
lineHeight: 1.5,
},
},
fonts: [
'https://raw.githubusercontent.com/notofonts/noto-cjk/main/Sans/SubsetOTF/SC/NotoSansSC-Bold.otf',
'https://raw.githubusercontent.com/notofonts/noto-cjk/main/Sans/SubsetOTF/SC/NotoSansSC-Regular.otf',
// 'https://raw.githubusercontent.com/notofonts/noto-cjk/main/Serif/SubsetOTF/SC/NotoSerifSC-Bold.otf',
// 'https://raw.githubusercontent.com/notofonts/noto-cjk/main/Serif/SubsetOTF/SC/NotoSerifSC-Regular.otf',
],
bgGradient: [[242, 241, 245]],
}),
})