fix: load CJK fonts in OG image route and prefer feature_image for Twitter cards

OG images rendered without fonts caused blank/tofu text for Chinese titles,
breaking Twitter card previews. Now loads Noto Sans TC with in-memory cache.
Blog posts also prefer feature_image when available for social card images.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-17 22:14:12 +08:00
parent 1f7dbd80d6
commit 1d4cfe773c
2 changed files with 31 additions and 2 deletions

View File

@@ -40,6 +40,11 @@ export async function generateMetadata({ params }: Props): Promise<Metadata> {
ogImageUrl.searchParams.set('tags', post.tags.slice(0, 3).join(','));
}
// Prefer post's feature_image for social cards; fall back to dynamic OG
const imageUrl = post.feature_image
? `${siteConfig.url}${post.feature_image.replace('../assets', '/assets')}`
: ogImageUrl.toString();
return {
title: post.title,
description: post.description || post.title,
@@ -61,7 +66,7 @@ export async function generateMetadata({ params }: Props): Promise<Metadata> {
tags: post.tags,
images: [
{
url: ogImageUrl.toString(),
url: imageUrl,
width: 1200,
height: 630,
alt: post.title,
@@ -72,7 +77,7 @@ export async function generateMetadata({ params }: Props): Promise<Metadata> {
card: 'summary_large_image',
title: post.title,
description: post.description || post.title,
images: [ogImageUrl.toString()],
images: [imageUrl],
},
};
}