LastUpdated.vue 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <template>
  2. <p v-if="hasLastUpdated" class="last-updated">
  3. <span class="prefix">{{ prefix }}:</span>
  4. <span class="datetime">{{ datetime }}</span>
  5. </p>
  6. </template>
  7. <script setup lang="ts">
  8. import { ref, computed, onMounted } from 'vue'
  9. import { useSiteDataByRoute, usePageData } from 'vitepress'
  10. const site = useSiteDataByRoute()
  11. const page = usePageData()
  12. const hasLastUpdated = computed(() => {
  13. const lu = site.value.themeConfig.lastUpdated
  14. return lu !== undefined && lu !== false
  15. })
  16. const prefix = computed(() => {
  17. const p = site.value.themeConfig.lastUpdated
  18. return p === true ? 'Last Updated' : p
  19. })
  20. const datetime = ref('')
  21. onMounted(() => {
  22. // locale string might be different based on end user
  23. // and will lead to potential hydration mismatch if calculated at build time
  24. datetime.value = new Date(page.value.lastUpdated).toLocaleString('en-US')
  25. })
  26. </script>
  27. <style scoped>
  28. .last-updated {
  29. display: inline-block;
  30. margin: 0;
  31. line-height: 1.4;
  32. font-size: 0.9rem;
  33. color: var(--c-text-light);
  34. }
  35. @media (min-width: 960px) {
  36. .last-updated {
  37. font-size: 1rem;
  38. }
  39. }
  40. .prefix {
  41. display: inline-block;
  42. font-weight: 500;
  43. }
  44. .datetime {
  45. display: inline-block;
  46. margin-left: 6px;
  47. font-weight: 400;
  48. }
  49. </style>