|
| 1 | +<script setup lang="ts"> |
| 2 | +import type { ResolvedAuthor } from '#shared/schemas/blog' |
| 3 | +
|
| 4 | +const { |
| 5 | + title, |
| 6 | + authors = [], |
| 7 | + date = '', |
| 8 | +} = defineProps<{ |
| 9 | + title: string |
| 10 | + authors?: ResolvedAuthor[] |
| 11 | + date?: string |
| 12 | +}>() |
| 13 | +
|
| 14 | +const formattedDate = computed(() => { |
| 15 | + if (!date) return '' |
| 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 | + }) |
| 25 | +}) |
| 26 | +
|
| 27 | +const MAX_VISIBLE_AUTHORS = 2 |
| 28 | +
|
| 29 | +const getInitials = (name: string) => |
| 30 | + name |
| 31 | + .trim() |
| 32 | + .split(/\s+/) |
| 33 | + .map(part => part[0] ?? '') |
| 34 | + .join('') |
| 35 | + .toUpperCase() |
| 36 | + .slice(0, 2) |
| 37 | +
|
| 38 | +const visibleAuthors = computed(() => { |
| 39 | + if (authors.length <= 3) return authors |
| 40 | + return authors.slice(0, MAX_VISIBLE_AUTHORS) |
| 41 | +}) |
| 42 | +
|
| 43 | +const extraCount = computed(() => { |
| 44 | + if (authors.length <= 3) return 0 |
| 45 | + return authors.length - MAX_VISIBLE_AUTHORS |
| 46 | +}) |
| 47 | +
|
| 48 | +const formattedAuthorNames = computed(() => { |
| 49 | + const allNames = authors.map(a => a.name) |
| 50 | + if (allNames.length === 0) return '' |
| 51 | + if (allNames.length === 1) return allNames[0] |
| 52 | + if (allNames.length === 2) return `${allNames[0]} and ${allNames[1]}` |
| 53 | + if (allNames.length === 3) return `${allNames[0]}, ${allNames[1]}, and ${allNames[2]}` |
| 54 | + const shown = allNames.slice(0, MAX_VISIBLE_AUTHORS) |
| 55 | + const remaining = allNames.length - MAX_VISIBLE_AUTHORS |
| 56 | + return `${shown.join(', ')} and ${remaining} others` |
| 57 | +}) |
| 58 | +</script> |
| 59 | + |
| 60 | +<template> |
| 61 | + <OgLayout> |
| 62 | + <div class="px-15 py-12 flex flex-col justify-center gap-5 h-full"> |
| 63 | + <OgBrand :height="48" /> |
| 64 | + |
| 65 | + <!-- Date + Title --> |
| 66 | + <div class="flex flex-col gap-2"> |
| 67 | + <span v-if="formattedDate" class="text-3xl text-fg-muted"> |
| 68 | + {{ formattedDate }} |
| 69 | + </span> |
| 70 | + |
| 71 | + <div |
| 72 | + class="lg:text-6xl text-5xl tracking-tighter font-mono leading-tight" |
| 73 | + :style="{ lineClamp: 2, textOverflow: 'ellipsis' }" |
| 74 | + > |
| 75 | + {{ title }} |
| 76 | + </div> |
| 77 | + </div> |
| 78 | + |
| 79 | + <!-- Authors --> |
| 80 | + <div v-if="authors.length" class="flex items-center gap-4 flex-nowrap"> |
| 81 | + <!-- Stacked avatars --> |
| 82 | + <span class="flex flex-row items-center"> |
| 83 | + <span |
| 84 | + v-for="(author, index) in visibleAuthors" |
| 85 | + :key="author.name" |
| 86 | + class="flex items-center justify-center rounded-full border border-bg bg-bg-muted overflow-hidden w-12 h-12" |
| 87 | + :style="{ marginLeft: index > 0 ? '-20px' : '0' }" |
| 88 | + > |
| 89 | + <img |
| 90 | + v-if="author.avatar" |
| 91 | + :src="author.avatar" |
| 92 | + :alt="author.name" |
| 93 | + width="48" |
| 94 | + height="48" |
| 95 | + class="w-full h-full object-cover" |
| 96 | + /> |
| 97 | + <span v-else class="text-5 text-fg-muted font-medium"> |
| 98 | + {{ getInitials(author.name) }} |
| 99 | + </span> |
| 100 | + </span> |
| 101 | + <!-- +N badge --> |
| 102 | + <span |
| 103 | + v-if="extraCount > 0" |
| 104 | + class="flex items-center justify-center text-lg font-medium text-fg-muted rounded-full border border-bg bg-bg-muted overflow-hidden w-12 h-12" |
| 105 | + :style="{ marginLeft: '-20px' }" |
| 106 | + > |
| 107 | + +{{ extraCount }} |
| 108 | + </span> |
| 109 | + </span> |
| 110 | + <!-- Names --> |
| 111 | + <span class="text-6 text-fg-muted font-light">{{ formattedAuthorNames }}</span> |
| 112 | + </div> |
| 113 | + </div> |
| 114 | + </OgLayout> |
| 115 | +</template> |
0 commit comments