@@ -6,6 +6,7 @@ import { loadOgAssets } from './assets.server'
66import { getAccentColor } from './colors'
77import { buildOgTree } from './template'
88
9+ const MAX_TITLE_LENGTH = 80
910const MAX_DESCRIPTION_LENGTH = 160
1011
1112type GenerateInput = {
@@ -30,10 +31,12 @@ export async function generateOgPng(
3031 const assets = loadOgAssets ( )
3132 const accentColor = getAccentColor ( library . id )
3233 const libraryName = library . name
33- const docTitle = input . title ?. trim ( ) || undefined
34+ const docTitle = input . title ?. trim ( )
35+ ? clampText ( input . title . trim ( ) , MAX_TITLE_LENGTH )
36+ : undefined
3437 const rawDescription =
3538 input . description ?. trim ( ) || library . tagline || library . description || ''
36- const description = clampDescription ( rawDescription )
39+ const description = clampText ( rawDescription , MAX_DESCRIPTION_LENGTH )
3740
3841 const tree = buildOgTree ( {
3942 libraryName,
@@ -58,7 +61,7 @@ export async function generateOgPng(
5861 return resvg . render ( ) . asPng ( )
5962}
6063
61- function clampDescription ( text : string ) : string {
62- if ( text . length <= MAX_DESCRIPTION_LENGTH ) return text
63- return text . slice ( 0 , MAX_DESCRIPTION_LENGTH - 1 ) . trimEnd ( ) + '…'
64+ function clampText ( text : string , max : number ) : string {
65+ if ( text . length <= max ) return text
66+ return text . slice ( 0 , max - 1 ) . trimEnd ( ) + '…'
6467}
0 commit comments