Skip to content

Commit d7baaa8

Browse files
committed
fix(docs): missing handle of invalid date
1 parent 0f6cfc2 commit d7baaa8

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

docs/.vitepress/custom/Docs.vue

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { DefaultTheme } from 'vitepress/theme'
33
44
import type { Author } from '../functions/authors.data'
55
6+
import { tryCatch } from '@moeru/std'
67
import { intlFormat } from 'date-fns'
78
import { AvatarFallback, AvatarImage, AvatarRoot } from 'reka-ui'
89
import { Content, useData, useRoute } from 'vitepress'
@@ -56,14 +57,25 @@ const publishedAt = computed(() => {
5657
if (frontmatter.value.publishedAtOverride) {
5758
return frontmatter.value.publishedAtOverride
5859
}
60+
61+
let date: string = ''
5962
if (frontmatter.value.publishedAt) {
60-
return intlFormat(new Date(frontmatter.value.publishedAt), { dateStyle: 'long' })
63+
date = frontmatter.value.publishedAt
6164
}
6265
if (frontmatter.value.date) {
63-
return intlFormat(new Date(frontmatter.value.data), { dateStyle: 'long' })
66+
date = frontmatter.value.data
67+
}
68+
if (!date) {
69+
return undefined
70+
}
71+
72+
const { data, error } = tryCatch(() => intlFormat(new Date(frontmatter.value.publishedAt), { dateStyle: 'long' }))
73+
if (error) {
74+
console.error('Error formatting publishedAt date:', error)
75+
return undefined
6476
}
6577
66-
return undefined
78+
return data
6779
})
6880
6981
const authors = computed(() => {

0 commit comments

Comments
 (0)