Skip to content

Commit fc1e79c

Browse files
committed
chore: bump module + sync
1 parent 427133a commit fc1e79c

File tree

11 files changed

+408
-130
lines changed

11 files changed

+408
-130
lines changed

app/components/OgImage/BlogPost.takumi.vue

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,24 @@ const {
1313
1414
const formattedDate = computed(() => {
1515
if (!date) return ''
16-
try {
17-
return new Date(date).toLocaleDateString('en-US', {
18-
year: 'numeric',
19-
month: 'short',
20-
day: 'numeric',
21-
})
22-
} catch {
23-
return date
24-
}
16+
const parsed = new Date(date)
17+
if (Number.isNaN(parsed.getTime())) return date
18+
19+
return parsed.toLocaleDateString('en-US', {
20+
year: 'numeric',
21+
month: 'short',
22+
day: 'numeric',
23+
timeZone: 'UTC',
24+
})
2525
})
2626
2727
const MAX_VISIBLE_AUTHORS = 2
2828
2929
const getInitials = (name: string) =>
3030
name
31-
.split(' ')
32-
.map(n => n[0])
31+
.trim()
32+
.split(/\s+/)
33+
.map(part => part[0] ?? '')
3334
.join('')
3435
.toUpperCase()
3536
.slice(0, 2)

app/components/OgImage/Package.takumi.vue

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,26 @@ import type { JsDelivrFileNode } from '#shared/types'
1717
import { joinURL } from 'ufo'
1818
import { smoothPath, useCharts } from '~/composables/useCharts'
1919
20+
const REPO_PROVIDER_ICONS: Record<string, string> = {
21+
github: 'i-simple-icons:github',
22+
gitlab: 'i-simple-icons:gitlab',
23+
bitbucket: 'i-simple-icons:bitbucket',
24+
codeberg: 'i-simple-icons:codeberg',
25+
gitea: 'i-simple-icons:gitea',
26+
forgejo: 'i-simple-icons:forgejo',
27+
gitee: 'i-simple-icons:gitee',
28+
sourcehut: 'i-simple-icons:sourcehut',
29+
tangled: 'i-custom:tangled',
30+
radicle: 'i-lucide:network',
31+
}
32+
33+
function sortJsDelivrNodes(nodes: JsDelivrFileNode[]) {
34+
return [...nodes].sort((a, b) => {
35+
if (a.type !== b.type) return a.type === 'directory' ? -1 : 1
36+
return a.name.localeCompare(b.name)
37+
})
38+
}
39+
2040
const { name, version, variant } = defineProps<{
2141
name: string
2242
version: string | null
@@ -55,6 +75,10 @@ const repositoryUrl = computed(() => {
5575
})
5676
5777
const { repoRef, stars, refresh: refreshRepoMeta } = useRepoMeta(repositoryUrl)
78+
const repoProviderIcon = computed(() => {
79+
const provider = repoRef.value?.provider
80+
return provider ? (REPO_PROVIDER_ICONS[provider] ?? 'i-lucide:code') : 'i-lucide:code'
81+
})
5882
5983
const formattedStars = computed(() => (stars.value > 0 ? compactFormat.format(stars.value) : ''))
6084
@@ -104,22 +128,15 @@ async function fetchCodeTree() {
104128
// Call jsDelivr directly — $fetch to internal API can deadlock in OG image island context
105129
const resp = await $fetch<{ files: JsDelivrFileNode[] }>(
106130
`https://data.jsdelivr.com/v1/packages/npm/${name}@${ver}`,
131+
{ timeout: 3000 },
107132
).catch(() => null)
108133
if (!resp?.files) return
109134
110135
const rows: TreeRow[] = []
111136
const MAX_ROWS = 25
112137
113-
// Sort: directories first, then files, alphabetical within each group
114-
function sorted(nodes: JsDelivrFileNode[]) {
115-
return [...nodes].sort((a, b) => {
116-
if (a.type !== b.type) return a.type === 'directory' ? -1 : 1
117-
return a.name.localeCompare(b.name)
118-
})
119-
}
120-
121138
function walk(nodes: JsDelivrFileNode[], depth: number) {
122-
for (const node of sorted(nodes)) {
139+
for (const node of sortJsDelivrNodes(nodes)) {
123140
if (rows.length >= MAX_ROWS) return
124141
rows.push({ name: node.name, depth, isDir: node.type === 'directory' })
125142
if (node.files) walk(node.files, depth + 1)
@@ -275,7 +292,7 @@ const sparklineSrc = computed(() => {
275292
<div class="flex flex-col gap-3 text-4xl text-fg-muted">
276293
<div v-if="repositoryUrl" class="flex items-center gap-2">
277294
<div
278-
class="i-simple-icons:github shrink-0 text-fg-muted"
295+
:class="[repoProviderIcon, 'shrink-0 text-fg-muted']"
279296
style="width: 24px; height: 24px"
280297
/>
281298
<span v-if="repoRef" class="max-w-[500px]" style="text-overflow: ellipsis">

app/components/OgImage/Page.takumi.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const { title, description } = defineProps<{
1010
<div class="px-15 py-12 flex flex-col justify-center gap-12 h-full">
1111
<OgBrand :height="48" />
1212

13-
<div class="flex flex-col max-w-full gap-3">
13+
<div v-if="title" class="flex flex-col max-w-full gap-3">
1414
<div
1515
class="lg:text-7xl text-5xl tracking-tighter font-mono leading-none"
1616
:style="{ lineClamp: 1, textOverflow: 'ellipsis' }"

app/components/OgImage/Profile.takumi.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ const {
1717
1818
const getInitials = (name: string) =>
1919
name
20-
.split(' ')
21-
.map(n => n[0])
20+
.trim()
21+
.split(/\s+/)
22+
.map(part => part[0] ?? '')
2223
.join('')
2324
.toUpperCase()
2425
.slice(0, 2)

app/composables/useCharts.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,15 @@ function mergeDailyPoints(points: DailyRawPoint[]): DailyRawPoint[] {
6666
.map(([day, value]) => ({ day, value }))
6767
}
6868

69+
function roundToHundredths(value: number): number {
70+
return Math.round(value * 100) / 100
71+
}
72+
6973
/** Catmull-Rom monotone cubic spline — same algorithm as vue-data-ui's smoothPath for OG Images */
7074
export function smoothPath(pts: { x: number; y: number }[]): string {
7175
if (pts.length < 2) return '0,0'
7276
const n = pts.length - 1
73-
const r = (v: number) => Math.round(v * 100) / 100
74-
const out = [`${r(pts[0]!.x)},${r(pts[0]!.y)}`]
77+
const out = [`${roundToHundredths(pts[0]!.x)},${roundToHundredths(pts[0]!.y)}`]
7578
const dx: number[] = []
7679
const dy: number[] = []
7780
const m: number[] = []
@@ -96,7 +99,7 @@ export function smoothPath(pts: { x: number; y: number }[]): string {
9699
y1 = pts[i + 1]!.y
97100
const seg = x1 - x0
98101
out.push(
99-
`C ${r(x0 + seg / 3)},${r(y0 + (t[i]! * seg) / 3)} ${r(x1 - seg / 3)},${r(y1 - (t[i + 1]! * seg) / 3)} ${r(x1)},${r(y1)}`,
102+
`C ${roundToHundredths(x0 + seg / 3)},${roundToHundredths(y0 + (t[i]! * seg) / 3)} ${roundToHundredths(x1 - seg / 3)},${roundToHundredths(y1 - (t[i + 1]! * seg) / 3)} ${roundToHundredths(x1)},${roundToHundredths(y1)}`,
100103
)
101104
}
102105

modules/runtime/server/cache.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ function getMockForUrl(url: string): MockResult | null {
193193
if (rangeMatch?.[1] && rangeMatch[2]) {
194194
const [startDate, endDate] = rangeMatch[1].split(':')
195195
const packageName = rangeMatch[2]
196+
if (!startDate || !endDate) return null
196197
// Simple hash seeded by package name for deterministic but varied curves
197198
let h = 0
198199
for (const c of packageName) h = ((h << 5) - h + c.charCodeAt(0)) | 0
@@ -208,20 +209,24 @@ function getMockForUrl(url: string): MockResult | null {
208209
const weekendDip = 0.3 + ((s >> 16) % 40) / 100 // 0.30 .. 0.70
209210

210211
const downloads: { day: string; downloads: number }[] = []
211-
const start = new Date(startDate!)
212-
const end = new Date(endDate!)
213-
for (let d = new Date(start); d <= end; d.setUTCDate(d.getUTCDate() + 1)) {
214-
const day = d.toISOString().slice(0, 10)
212+
const start = new Date(startDate)
213+
const end = new Date(endDate)
214+
if (Number.isNaN(start.getTime()) || Number.isNaN(end.getTime())) return null
215+
216+
const cursor = new Date(start)
217+
while (cursor.getTime() <= end.getTime()) {
218+
const day = cursor.toISOString().slice(0, 10)
215219
const i = downloads.length
216220
const trend = 1 + trendSlope * i
217221
const wave = Math.sin((i * 2 * Math.PI) / wavePeriod) * waveAmp
218222
const noise = Math.sin(i * 7 + s) * 0.05
219-
const dow = d.getUTCDay()
223+
const dow = cursor.getUTCDay()
220224
const weekend = dow === 0 || dow === 6 ? 1 - weekendDip : 1
221225
downloads.push({
222226
day,
223227
downloads: Math.max(0, Math.round(base * trend * (1 + wave + noise) * weekend)),
224228
})
229+
cursor.setUTCDate(cursor.getUTCDate() + 1)
225230
}
226231
return { data: { downloads, start: startDate, end: endDate, package: packageName } }
227232
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
"marked": "18.0.0",
9292
"module-replacements": "2.11.0",
9393
"nuxt": "4.3.1",
94-
"nuxt-og-image": "6.3.10",
94+
"nuxt-og-image": "^6.4.3",
9595
"ofetch": "1.5.1",
9696
"ohash": "2.0.11",
9797
"perfect-debounce": "2.1.0",

0 commit comments

Comments
 (0)