Skip to content

Commit be36333

Browse files
committed
Update: 最后更新时间计算修复
1 parent dc0fc93 commit be36333

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

package/components/NanoMain/index.vue

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
style="padding: calc(var(--base-size) * 2.5) calc(var(--base-size) * 1.5) 0"
3030
>
3131
<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>
3333
</div>
3434
<slot name="contentAfter">
3535
<NanoComment/>
@@ -45,17 +45,18 @@
4545
import 'overlayscrollbars/styles/overlayscrollbars.css';
4646
import scrollbarOptions from '../../config/scrollbarOptions';
4747
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';
4949
import { onContentUpdated, useData, useRoute } from 'vitepress';
5050
import emitter from '../../emitter';
5151
import NotFound from 'vitepress/dist/client/theme-default/NotFound.vue';
52-
import dayjs from 'dayjs';
5352
54-
const { page } = useData();
53+
const { page, theme, frontmatter } = useData();
5554
const route = useRoute();
5655
const scrollbars = ref<InstanceType<typeof OverlayScrollbarsComponent> | null>(null);
5756
const article = ref<HTMLElement | null>(null);
5857
58+
const datetime = ref('');
59+
5960
// Listen for routing changes and scroll to the top
6061
watch(() => route.path, () => {
6162
nextTick(() => {
@@ -90,7 +91,20 @@
9091
const resizeObserver = ref<ResizeObserver | null>(null);
9192
const articlePadding = ref<string>('calc(var(--base-size))');
9293
94+
const date = computed(
95+
() => new Date(frontmatter.value.lastUpdated ?? page.value.lastUpdated)
96+
);
97+
9398
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+
});
94108
// console.log('mounted');
95109
// Listen for scroll-to-hash events
96110
emitter.on('scroll-to-hash', (hash: string) => {

0 commit comments

Comments
 (0)