Skip to content

Commit

Permalink
fix(theme): make last updated time reactive (#879)
Browse files Browse the repository at this point in the history
  • Loading branch information
RainKolwa authored Jun 29, 2022
1 parent 29d44e7 commit 25a835f
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
<script setup lang="ts">
import { ref, watchEffect, onMounted } from 'vue'
import { ref, computed, watchEffect, onMounted } from 'vue'
import { useData } from 'vitepress'
const { theme, page } = useData()
const date = new Date(page.value.lastUpdated!)
const isoDatetime = date.toISOString()
const date = computed(() => new Date(page.value.lastUpdated!))
const isoDatetime = computed(() => date.value.toISOString())
const datetime = ref('')
// set time on mounted hook because the locale string might be different
// based on end user and will lead to potential hydration mismatch if
// calculated at build time
onMounted(() => {
watchEffect(() => {
datetime.value = date.toLocaleString(window.navigator.language)
datetime.value = date.value.toLocaleString(window.navigator.language)
})
})
</script>
Expand Down

0 comments on commit 25a835f

Please sign in to comment.