Skip to content

Commit f1de297

Browse files
committed
docs: infer OG image category from page path, increase font sizes
1 parent 24fe0f5 commit f1de297

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

apps/docs/build/generate-og-images.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ import { fileURLToPath } from 'node:url'
66
import { Resvg } from '@resvg/resvg-js'
77
import satori from 'satori'
88

9+
// Types
10+
import type { Frontmatter } from './frontmatter'
11+
912
import { getApiNamesGrouped } from './api-names'
1013
import { parseFrontmatter } from './frontmatter'
1114

@@ -47,6 +50,20 @@ function cleanTitle (raw: string): string {
4750
return raw.includes(' - ') ? raw.split(' - ')[0] : raw
4851
}
4952

53+
const CATEGORY_MAP: Record<string, string> = {
54+
introduction: 'Introduction',
55+
guide: 'Guide',
56+
components: 'Components',
57+
composables: 'Composables',
58+
utilities: 'Utilities',
59+
api: 'API Reference',
60+
}
61+
62+
function inferCategory (path: string, frontmatter: Frontmatter): string | undefined {
63+
if (frontmatter.features?.category) return frontmatter.features.category
64+
return CATEGORY_MAP[path.split('/')[1]]
65+
}
66+
5067
function template (title: string, description: string, category?: string) {
5168
return {
5269
type: 'div',
@@ -111,7 +128,7 @@ function template (title: string, description: string, category?: string) {
111128
type: 'div',
112129
props: {
113130
style: {
114-
fontSize: '56px',
131+
fontSize: '76px',
115132
fontWeight: 700,
116133
lineHeight: '1.2',
117134
marginBottom: '24px',
@@ -125,7 +142,7 @@ function template (title: string, description: string, category?: string) {
125142
type: 'div',
126143
props: {
127144
style: {
128-
fontSize: '26px',
145+
fontSize: '34px',
129146
color: 'rgba(255, 255, 255, 0.7)',
130147
lineHeight: '1.5',
131148
},
@@ -184,11 +201,12 @@ export async function generateOgImages (): Promise<void> {
184201

185202
if (!frontmatter.title) continue
186203

204+
const path = getPath(file)
187205
files.push({
188-
path: getPath(file),
206+
path,
189207
title: cleanTitle(frontmatter.title),
190208
description: frontmatter.description ?? '',
191-
category: frontmatter.features?.category,
209+
category: inferCategory(path, frontmatter),
192210
})
193211
}
194212

0 commit comments

Comments
 (0)