Skip to content

Commit 5cc9f20

Browse files
authored
feat: add stars to open graph images for package pages (#545)
1 parent 7bd3c5d commit 5cc9f20

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

app/components/OgImage/Package.vue

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
<script setup lang="ts">
2-
withDefaults(
2+
import { computed, toRefs } from 'vue'
3+
4+
const props = withDefaults(
35
defineProps<{
46
name: string
57
version: string
8+
stars: number
69
downloads?: string
710
license?: string
811
primaryColor?: string
@@ -13,6 +16,15 @@ withDefaults(
1316
primaryColor: '#60a5fa',
1417
},
1518
)
19+
20+
const { name, version, stars, downloads, license, primaryColor } = toRefs(props)
21+
22+
const formattedStars = computed(() =>
23+
Intl.NumberFormat('en', {
24+
notation: 'compact',
25+
maximumFractionDigits: 1,
26+
}).format(stars.value),
27+
)
1628
</script>
1729

1830
<template>
@@ -88,6 +100,18 @@ withDefaults(
88100
</span>
89101
</span>
90102
<span v-if="license"> • {{ license }}</span>
103+
<span class="flex items-center gap-2">
104+
<span>•</span>
105+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32" width="32px" height="32px">
106+
<path
107+
fill="currentColor"
108+
d="m16 6.52l2.76 5.58l.46 1l1 .15l6.16.89l-4.38 4.3l-.75.73l.18 1l1.05 6.13l-5.51-2.89L16 23l-.93.49l-5.51 2.85l1-6.13l.18-1l-.74-.77l-4.42-4.35l6.16-.89l1-.15l.46-1zM16 2l-4.55 9.22l-10.17 1.47l7.36 7.18L6.9 30l9.1-4.78L25.1 30l-1.74-10.13l7.36-7.17l-10.17-1.48Z"
109+
/>
110+
</svg>
111+
<span>
112+
{{ formattedStars }}
113+
</span>
114+
</span>
91115
</div>
92116
</div>
93117

app/pages/[...package].vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ defineOgImageComponent('Package', {
350350
version: () => displayVersion.value?.version ?? '',
351351
downloads: () => (downloads.value ? $n(downloads.value.downloads) : ''),
352352
license: () => pkg.value?.license ?? '',
353+
stars: () => stars.value ?? 0,
353354
primaryColor: '#60a5fa',
354355
})
355356

0 commit comments

Comments
 (0)