Skip to content

Commit bb50459

Browse files
author
guanchen.lin
committed
feat: add social cards for pricing research
1 parent b183544 commit bb50459

2 files changed

Lines changed: 102 additions & 0 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { ImageResponse } from 'next/og';
2+
import { ogTemplate, OG_SIZE, OG_CONTENT_TYPE } from '@/lib/og-template';
3+
import { isPricingGuideSlug, PRICING_GUIDES } from '@/lib/pricing-guides';
4+
import { decodeSlugParam } from '@/lib/route-params';
5+
6+
export const alt = 'AI API Pricing Guide - aiplans.dev';
7+
export const size = OG_SIZE;
8+
export const contentType = OG_CONTENT_TYPE;
9+
10+
export default async function Image({
11+
params,
12+
}: {
13+
params: Promise<{ locale: string; slug: string }>;
14+
}) {
15+
const { locale, slug: rawSlug } = await params;
16+
const slug = decodeSlugParam(rawSlug);
17+
const isZh = locale === 'zh';
18+
const guide = isPricingGuideSlug(slug) ? PRICING_GUIDES[slug] : null;
19+
20+
return new ImageResponse(
21+
ogTemplate({
22+
kicker: isZh ? 'API 价格指南' : 'API Pricing Guide',
23+
title: guide?.title[isZh ? 'zh' : 'en'] ?? slug,
24+
subtitle: guide?.description[isZh ? 'zh' : 'en']
25+
?? (isZh ? '模型、渠道与 token 成本对比' : 'Models, channels, and token cost comparisons'),
26+
stats: isZh
27+
? [
28+
{ label: '数据', value: '持续更新' },
29+
{ label: '价格来源', value: '可核验' },
30+
{ label: '成本示例', value: '可复算' },
31+
]
32+
: [
33+
{ label: 'Data', value: 'Live' },
34+
{ label: 'Sources', value: 'Auditable' },
35+
{ label: 'Examples', value: 'Reproducible' },
36+
],
37+
accent: '#0f766e',
38+
locale: isZh ? 'zh' : 'en',
39+
}),
40+
size,
41+
);
42+
}
43+
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { ImageResponse } from 'next/og';
2+
import { getPriceIndexSnapshot } from '@/lib/api-price-index';
3+
import { ogTemplate, OG_SIZE, OG_CONTENT_TYPE } from '@/lib/og-template';
4+
5+
export const alt = 'AI API Price Index - aiplans.dev';
6+
export const size = OG_SIZE;
7+
export const contentType = OG_CONTENT_TYPE;
8+
export const revalidate = 21600;
9+
10+
export default async function Image({
11+
params,
12+
}: {
13+
params: Promise<{ locale: string }>;
14+
}) {
15+
const { locale } = await params;
16+
const isZh = locale === 'zh';
17+
const snapshot = await getPriceIndexSnapshot().catch((error: unknown) => {
18+
console.error('Failed to load API price index stats for Open Graph image', error);
19+
return null;
20+
});
21+
22+
const stats = snapshot
23+
? (isZh
24+
? [
25+
{ label: '定价模型', value: snapshot.modelCount.toLocaleString('zh-CN') },
26+
{ label: '可用渠道', value: snapshot.channelCount.toLocaleString('zh-CN') },
27+
{ label: '供应商', value: snapshot.providerCount.toLocaleString('zh-CN') },
28+
]
29+
: [
30+
{ label: 'Priced models', value: snapshot.modelCount.toLocaleString('en-US') },
31+
{ label: 'Channels', value: snapshot.channelCount.toLocaleString('en-US') },
32+
{ label: 'Providers', value: snapshot.providerCount.toLocaleString('en-US') },
33+
])
34+
: (isZh
35+
? [
36+
{ label: '价格数据', value: '持续更新' },
37+
{ label: '供应渠道', value: '多渠道' },
38+
{ label: '价格来源', value: '可核验' },
39+
]
40+
: [
41+
{ label: 'Price data', value: 'Live' },
42+
{ label: 'Coverage', value: 'Multi-channel' },
43+
{ label: 'Sources', value: 'Auditable' },
44+
]);
45+
46+
return new ImageResponse(
47+
ogTemplate({
48+
kicker: isZh ? '市场数据报告' : 'Market Data Report',
49+
title: isZh ? 'AI API 价格指数' : 'AI API Price Index',
50+
subtitle: isZh
51+
? '跨官方、云平台和聚合渠道对比当前 token 价格'
52+
: 'Current token prices across direct, cloud, and aggregator channels',
53+
stats,
54+
accent: '#0f766e',
55+
locale: isZh ? 'zh' : 'en',
56+
}),
57+
size,
58+
);
59+
}

0 commit comments

Comments
 (0)