docs/.vitepress/theme/components/SiteFooter.vue
65 lines · 1663 bytes
1<script setup lang="ts">
2import { useData } from 'vitepress'
3import { computed, onMounted, ref } from 'vue'
4
5const { page } = useData()
6const isHome = computed(() => page.value.relativePath === 'index.md')
7
8const commit = __GIT_COMMIT__
9const buildAge = ref('')
10
11onMounted(() => {
12 const diff = Math.floor(Date.now() / 1000 - __GIT_COMMIT_TS__)
13 const rtf = new Intl.RelativeTimeFormat('en', { numeric: 'auto' })
14 let label: string
15 if (diff < 3600) label = rtf.format(-Math.floor(diff / 60), 'minute')
16 else if (diff < 86400) label = rtf.format(-Math.floor(diff / 3600), 'hour')
17 else if (diff < 2592000) label = rtf.format(-Math.floor(diff / 86400), 'day')
18 else label = rtf.format(-Math.floor(diff / 2592000), 'month')
19 buildAge.value = `Updated ${label}`
20})
21</script>
22
23<template>
24 <footer v-if="isHome" class="site-footer">
25 <span class="footer-center">
26 <span v-if="buildAge">{{ buildAge }}</span>
27 <span v-if="buildAge" class="divider">|</span>
28 <a :href="`https://github.com/wotakumoe/Wotaku/commit/${commit}`" class="no-icon">{{ commit.slice(0, 7) }}</a>
29 </span>
30 </footer>
31</template>
32
33<style scoped>
34.site-footer {
35 display: flex;
36 justify-content: center;
37 align-items: center;
38 padding: 12px 24px;
39 font-size: 12px;
40 color: var(--vp-c-text-2);
41 background-color: var(--vp-c-bg-alt);
42}
43
44.footer-center {
45 display: flex;
46 align-items: center;
47 gap: 8px;
48}
49
50.divider {
51 color: var(--vp-c-divider);
52}
53
54a {
55 color: var(--vp-c-text-2);
56 text-decoration-line: underline;
57 text-decoration-style: dashed;
58 text-underline-offset: 5px;
59 transition: color 0.3s;
60}
61
62a:hover {
63 color: var(--vp-c-text-1);
64}
65</style>