Skip to content

Commit 9b2f0d2

Browse files
committed
fix: blog post published date
1 parent 64a3cf2 commit 9b2f0d2

3 files changed

Lines changed: 19 additions & 14 deletions

File tree

app/components/BlogPostListCard.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script setup lang="ts">
22
import type { Author } from '#shared/schemas/blog'
33
4-
defineProps<{
4+
const props = defineProps<{
55
/** Authors of the blog post */
66
authors: Author[]
77
/** Blog Title */
@@ -19,6 +19,8 @@ defineProps<{
1919
/** Whether this post is an unpublished draft */
2020
draft?: boolean
2121
}>()
22+
23+
const formattedPublished = computed(() => toLocaleDateString(props.published))
2224
</script>
2325

2426
<template>
@@ -33,7 +35,7 @@ defineProps<{
3335
<!-- Text Content -->
3436
<div class="flex-1 min-w-0 text-start gap-2">
3537
<div class="flex items-center gap-2">
36-
<span class="text-xs text-fg-muted font-mono">{{ published }}</span>
38+
<span class="text-xs text-fg-muted font-mono">{{ formattedPublished }}</span>
3739
<span
3840
v-if="draft"
3941
class="text-xs px-1.5 py-0.5 rounded badge-orange font-sans font-medium"

app/components/OgImage/BlogPost.vue

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,7 @@ const props = withDefaults(
1717
1818
const { resolvedAuthors } = useBlueskyAuthorProfiles(props.authors)
1919
20-
const formattedDate = computed(() => {
21-
if (!props.date) return ''
22-
try {
23-
return new Date(props.date).toLocaleDateString('en-US', {
24-
year: 'numeric',
25-
month: 'short',
26-
day: 'numeric',
27-
})
28-
} catch {
29-
return props.date
30-
}
31-
})
20+
const formattedDate = computed(() => toLocaleDateString(props.date))
3221
3322
const MAX_VISIBLE_AUTHORS = 2
3423

app/utils/formatters.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,17 @@ export function toIsoDateString(date: Date): string {
44
const day = String(date.getUTCDate()).padStart(2, '0')
55
return `${year}-${month}-${day}`
66
}
7+
8+
export function toLocaleDateString(date: string): string {
9+
if (!date) return ''
10+
11+
try {
12+
return new Date(date).toLocaleDateString('en-US', {
13+
year: 'numeric',
14+
month: 'short',
15+
day: 'numeric',
16+
})
17+
} catch {
18+
return date
19+
}
20+
}

0 commit comments

Comments
 (0)