|
29 | 29 | style="padding: calc(var(--base-size) * 2.5) calc(var(--base-size) * 1.5) 0" |
30 | 30 | > |
31 | 31 | <span class="text-gray">最后更新于:</span> |
32 | | - <strong class="text-slate-4">{{ dayjs(page.lastUpdated).format('YYYY-MM-DD HH:mm') }}</strong> |
| 32 | + <strong class="text-slate-4">{{ datetime }}</strong> |
33 | 33 | </div> |
34 | 34 | <slot name="contentAfter"> |
35 | 35 | <NanoComment/> |
|
45 | 45 | import 'overlayscrollbars/styles/overlayscrollbars.css'; |
46 | 46 | import scrollbarOptions from '../../config/scrollbarOptions'; |
47 | 47 | import { OverlayScrollbarsComponent } from 'overlayscrollbars-vue'; |
48 | | - import { nextTick, onMounted, onUnmounted, ref, watch } from 'vue'; |
| 48 | + import { computed, nextTick, onMounted, onUnmounted, ref, watch, watchEffect } from 'vue'; |
49 | 49 | import { onContentUpdated, useData, useRoute } from 'vitepress'; |
50 | 50 | import emitter from '../../emitter'; |
51 | 51 | import NotFound from 'vitepress/dist/client/theme-default/NotFound.vue'; |
52 | | - import dayjs from 'dayjs'; |
53 | 52 |
|
54 | | - const { page } = useData(); |
| 53 | + const { page, theme, frontmatter } = useData(); |
55 | 54 | const route = useRoute(); |
56 | 55 | const scrollbars = ref<InstanceType<typeof OverlayScrollbarsComponent> | null>(null); |
57 | 56 | const article = ref<HTMLElement | null>(null); |
58 | 57 |
|
| 58 | + const datetime = ref(''); |
| 59 | +
|
59 | 60 | // Listen for routing changes and scroll to the top |
60 | 61 | watch(() => route.path, () => { |
61 | 62 | nextTick(() => { |
|
90 | 91 | const resizeObserver = ref<ResizeObserver | null>(null); |
91 | 92 | const articlePadding = ref<string>('calc(var(--base-size))'); |
92 | 93 |
|
| 94 | + const date = computed( |
| 95 | + () => new Date(frontmatter.value.lastUpdated ?? page.value.lastUpdated) |
| 96 | + ); |
| 97 | +
|
93 | 98 | onMounted(() => { |
| 99 | + watchEffect(() => { |
| 100 | + datetime.value = new Intl.DateTimeFormat( |
| 101 | + undefined, |
| 102 | + theme.value.lastUpdated?.formatOptions ?? { |
| 103 | + dateStyle: 'short', |
| 104 | + timeStyle: 'short' |
| 105 | + } |
| 106 | + ).format(date.value); |
| 107 | + }); |
94 | 108 | // console.log('mounted'); |
95 | 109 | // Listen for scroll-to-hash events |
96 | 110 | emitter.on('scroll-to-hash', (hash: string) => { |
|
0 commit comments