1
1
<script setup lang="ts">
2
- import { computed , inject , ref } from ' vue'
2
+ import { computed , inject , onMounted , ref } from ' vue'
3
3
import { differenceInDays , toDate } from ' date-fns'
4
4
import { useData } from ' vitepress'
5
5
@@ -23,27 +23,25 @@ const { t } = useI18n()
23
23
const rawPath = useRawPath ()
24
24
const commits = useCommits (Changelog .commits , rawPath )
25
25
26
+ const lastChangeDate = ref <Date >(toDate (commits .value [0 ]?.date_timestamp ))
27
+
26
28
const locale = computed <Locale >(() => {
27
29
if (! options .locales || typeof options .locales === ' undefined' )
28
30
return defaultLocales [lang .value ] || defaultEnLocale || {}
29
31
30
32
return options .locales [lang .value ] || defaultEnLocale || {}
31
33
})
32
34
33
- const lastChangeDate = computed (() => {
34
- const dateTimestamp: number = commits .value [0 ]?.date_timestamp || 0
35
- if (! dateTimestamp )
36
- return new Date ()
37
-
38
- return toDate (dateTimestamp )
39
- })
40
-
41
35
const isFreshChange = computed (() => {
42
36
if (! lastChangeDate .value )
43
37
return false
44
38
45
39
return differenceInDays (new Date (), lastChangeDate .value ) < 1
46
40
})
41
+
42
+ onMounted (() => {
43
+ lastChangeDate .value = toDate (commits .value [0 ]?.date_timestamp )
44
+ })
47
45
</script >
48
46
49
47
<template >
@@ -102,9 +100,11 @@ const isFreshChange = computed(() => {
102
100
<a :href =" commit.release_tag_url" target =" _blank" >
103
101
<code class =" font-bold" >{{ commit.tag }}</code >
104
102
</a >
105
- <span class =" text-xs opacity-50" >
106
- {{ t('committedOn', { props: { date: new Date(commit.date).toLocaleDateString() } }) }}
107
- </span >
103
+ <ClientOnly >
104
+ <span class =" text-xs opacity-50" :title =" toDate(commit.date_timestamp).toString()" >
105
+ {{ t('committedOn', { props: { date: toDate(commit.date_timestamp).toLocaleDateString() } }) }}
106
+ </span >
107
+ </ClientOnly >
108
108
</div >
109
109
</template >
110
110
<template v-else >
@@ -122,9 +122,11 @@ const isFreshChange = computed(() => {
122
122
<span >-</span >
123
123
<span >
124
124
<span class =" text-sm <sm:text-xs" v-html =" renderCommitMessage(commit.repo_url || 'https://github.com/example/example', commit.message)" />
125
- <span class =" text-xs opacity-50" >
126
- {{ t('committedOn', { props: { date: new Date(commit.date).toLocaleDateString() } }) }}
127
- </span >
125
+ <ClientOnly >
126
+ <span class =" text-xs opacity-50" :title =" toDate(commit.date_timestamp).toString()" >
127
+ {{ t('committedOn', { props: { date: toDate(commit.date_timestamp).toLocaleDateString() } }) }}
128
+ </span >
129
+ </ClientOnly >
128
130
</span >
129
131
</div >
130
132
</template >
0 commit comments