Skip to content

Commit 775e4b8

Browse files
alexdlnorta
andauthored
fix: configure name scale in package og (#1466)
Co-authored-by: orta <git@orta.io>
1 parent cad008c commit 775e4b8

File tree

12 files changed

+59
-20
lines changed

12 files changed

+59
-20
lines changed

app/components/OgImage/Default.vue

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ const props = withDefaults(defineProps<Props>(), {
1515
<template>
1616
<div
1717
class="h-full w-full flex flex-col justify-center px-20 bg-[#050505] text-[#fafafa] relative overflow-hidden"
18+
style="font-family: 'Geist Mono', sans-serif"
1819
>
1920
<div class="relative z-10 flex flex-col gap-6">
2021
<div class="flex items-start gap-4">
2122
<div
22-
class="flex items-start justify-center w-16 h-16 rounded-xl bg-gradient-to-tr from-[#3b82f6] shadow-lg"
23+
class="flex items-start justify-center w-16 h-16 p-3.5 rounded-xl bg-gradient-to-tr from-[#3b82f6] shadow-lg"
2324
:style="{ backgroundColor: props.primaryColor }"
2425
>
2526
<svg
@@ -41,17 +42,19 @@ const props = withDefaults(defineProps<Props>(), {
4142
</svg>
4243
</div>
4344

44-
<h1
45-
class="text-8xl font-bold tracking-tighter"
46-
style="font-family: 'Geist Sans', sans-serif"
47-
>
48-
<span class="opacity-80" :style="{ color: props.primaryColor }">./</span>{{ props.title }}
45+
<h1 class="text-8xl font-bold">
46+
<span
47+
class="opacity-80 tracking-[-0.1em]"
48+
:style="{ color: props.primaryColor }"
49+
style="margin-left: -1rem; margin-right: 0.5rem"
50+
>./</span
51+
>{{ props.title }}
4952
</h1>
5053
</div>
5154

5255
<div
53-
class="flex flex-wrap items-center gap-x-3 text-4xl font-light text-[#a3a3a3]"
54-
style="font-family: 'Geist Sans', sans-serif"
56+
class="flex flex-wrap items-center gap-x-3 text-4xl text-[#a3a3a3]"
57+
style="font-family: 'Geist', sans-serif"
5558
>
5659
<template v-for="(part, index) in props.description.split(/(\*\*.*?\*\*)/)" :key="index">
5760
<span

app/components/OgImage/Package.vue

Lines changed: 39 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,22 @@ const formattedStars = computed(() =>
6464
: '',
6565
)
6666
67+
const MAX_LOGO_SYMBOLS = 40
68+
69+
const titleTruncated = computed(() => {
70+
return name.value.length > MAX_LOGO_SYMBOLS
71+
? `${name.value.slice(0, MAX_LOGO_SYMBOLS - 1)}…`
72+
: name.value
73+
})
74+
75+
// Dynamic font sizing based on name length
76+
// OG images are 1200px wide, with 64px padding on each side = 1072px content width
77+
// The original size (8xl) can fit 19 characters (2 logo characters + 17 name characters)
78+
const titleScale = computed(() => {
79+
const len = titleTruncated.value.length + 2
80+
return Math.min(Math.floor((19 / len) * 100) / 100, 1)
81+
})
82+
6783
try {
6884
await refreshPkg()
6985
await Promise.all([refreshRepoMeta(), refreshDownloads(), refreshLikes()])
@@ -78,12 +94,13 @@ try {
7894
<template>
7995
<div
8096
class="h-full w-full flex flex-col justify-center px-20 bg-[#050505] text-[#fafafa] relative overflow-hidden"
97+
style="font-family: 'Geist Mono', sans-serif"
8198
>
8299
<div class="relative z-10 flex flex-col gap-6">
83100
<!-- Package name -->
84101
<div class="flex items-start gap-4">
85102
<div
86-
class="flex items-center justify-center w-16 h-16 p-4 rounded-xl shadow-lg bg-gradient-to-tr from-[#3b82f6]"
103+
class="flex items-center justify-center w-16 h-16 p-3.5 rounded-xl shadow-lg bg-gradient-to-tr from-[#3b82f6]"
87104
:style="{ backgroundColor: primaryColor }"
88105
>
89106
<svg
@@ -106,18 +123,20 @@ try {
106123
</div>
107124

108125
<h1
109-
class="text-8xl font-bold tracking-tighter"
110-
style="font-family: 'Geist Sans', sans-serif"
126+
class="font-bold text-8xl origin-cl tracking-tighter text-nowrap whitespace-nowrap flex flex-nowrap"
127+
:style="{ transform: `scale(${titleScale})` }"
111128
>
112-
<span :style="{ color: primaryColor }" class="opacity-80">./</span>{{ pkg?.name }}
129+
<span
130+
:style="{ color: primaryColor }"
131+
class="opacity-80 tracking-[-0.1em]"
132+
style="margin-left: -0.5rem; margin-right: 1rem"
133+
>./</span
134+
>{{ titleTruncated }}
113135
</h1>
114136
</div>
115137

116138
<!-- Version -->
117-
<div
118-
class="flex items-center gap-5 text-4xl font-light text-[#a3a3a3]"
119-
style="font-family: 'Geist Sans', sans-serif"
120-
>
139+
<div class="flex items-center gap-5 text-3xl font-light text-[#a3a3a3]">
121140
<span
122141
class="px-3 py-1 me-2 rounded-lg border font-bold opacity-90"
123142
:style="{
@@ -127,11 +146,11 @@ try {
127146
boxShadow: `0 0 20px ${primaryColor}25`,
128147
}"
129148
>
130-
{{ resolvedVersion }}
149+
{{ resolvedVersion ?? version }}
131150
</span>
132151

133152
<!-- Downloads (if any) -->
134-
<span v-if="downloads" class="flex items-center gap-2">
153+
<span v-if="downloads" class="flex items-center gap-2 tracking-tight">
135154
<svg
136155
width="30"
137156
height="30"
@@ -175,7 +194,11 @@ try {
175194
</span>
176195

177196
<!-- Stars (if any) -->
178-
<span v-if="formattedStars" class="flex items-center gap-2" data-testid="stars">
197+
<span
198+
v-if="formattedStars"
199+
class="flex items-center gap-2 tracking-tight"
200+
data-testid="stars"
201+
>
179202
<svg
180203
xmlns="http://www.w3.org/2000/svg"
181204
viewBox="0 0 32 32"
@@ -194,7 +217,11 @@ try {
194217
</span>
195218

196219
<!-- Likes (if any) -->
197-
<span v-if="likes.totalLikes > 0" class="flex items-center gap-2" data-testid="likes">
220+
<span
221+
v-if="likes.totalLikes > 0"
222+
class="flex items-center gap-2 tracking-tight"
223+
data-testid="likes"
224+
>
198225
<svg
199226
width="32"
200227
height="32"

nuxt.config.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,15 @@ export default defineNuxtConfig({
247247
defaults: {
248248
component: 'Default',
249249
},
250+
fonts: [
251+
{ name: 'Geist', weight: 400, path: '/fonts/Geist-Regular.ttf' },
252+
{ name: 'Geist', weight: 500, path: '/fonts/Geist-Medium.ttf' },
253+
{ name: 'Geist', weight: 600, path: '/fonts/Geist-SemiBold.ttf' },
254+
{ name: 'Geist', weight: 700, path: '/fonts/Geist-Bold.ttf' },
255+
{ name: 'Geist Mono', weight: 400, path: '/fonts/GeistMono-Regular.ttf' },
256+
{ name: 'Geist Mono', weight: 500, path: '/fonts/GeistMono-Medium.ttf' },
257+
{ name: 'Geist Mono', weight: 700, path: '/fonts/GeistMono-Bold.ttf' },
258+
],
250259
},
251260

252261
pwa: {

public/fonts/Geist-Bold.ttf

70.1 KB
Binary file not shown.

public/fonts/Geist-Medium.ttf

70.4 KB
Binary file not shown.

public/fonts/Geist-Regular.ttf

69.4 KB
Binary file not shown.

public/fonts/Geist-SemiBold.ttf

70.4 KB
Binary file not shown.

public/fonts/GeistMono-Bold.ttf

68.2 KB
Binary file not shown.

public/fonts/GeistMono-Medium.ttf

68.4 KB
Binary file not shown.

public/fonts/GeistMono-Regular.ttf

68.3 KB
Binary file not shown.

0 commit comments

Comments
 (0)