Percy Ma 3 years ago committed by GitHub
parent 1db3730a48
commit 7210449275
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -4,6 +4,7 @@ export default defineConfig({
lang: 'en-US', lang: 'en-US',
title: 'VitePress', title: 'VitePress',
description: 'Vite & Vue powered static site generator.', description: 'Vite & Vue powered static site generator.',
lastUpdated: true,
themeConfig: { themeConfig: {
nav: nav(), nav: nav(),

@ -5,8 +5,9 @@ import { useEditLink } from '../composables/edit-link'
import { usePrevNext } from '../composables/prev-next' import { usePrevNext } from '../composables/prev-next'
import VPIconEdit from './icons/VPIconEdit.vue' import VPIconEdit from './icons/VPIconEdit.vue'
import VPLink from './VPLink.vue' import VPLink from './VPLink.vue'
import VPLastUpdated from './VPLastUpdated.vue'
const { theme, frontmatter } = useData() const { theme, page, frontmatter } = useData()
const editLink = useEditLink() const editLink = useEditLink()
const control = usePrevNext() const control = usePrevNext()
@ -14,12 +15,17 @@ const control = usePrevNext()
<template> <template>
<footer v-if="control.prev || control.next" class="VPDocFooter"> <footer v-if="control.prev || control.next" class="VPDocFooter">
<div class="edit-info">
<div v-if="theme.editLink && frontmatter.editLink !== false" class="edit-link"> <div v-if="theme.editLink && frontmatter.editLink !== false" class="edit-link">
<VPLink class="edit-link-button" :href="editLink.url" :no-icon="true"> <VPLink class="edit-link-button" :href="editLink.url" :no-icon="true">
<VPIconEdit class="edit-link-icon" /> <VPIconEdit class="edit-link-icon" />
{{ editLink.text }} {{ editLink.text }}
</VPLink> </VPLink>
</div> </div>
<div v-if="page.lastUpdated">
<VPLastUpdated />
</div>
</div>
<div class="prev-next"> <div class="prev-next">
<div class="pager"> <div class="pager">
@ -43,6 +49,15 @@ const control = usePrevNext()
margin-top: 64px; margin-top: 64px;
} }
.edit-info {
display: flex;
justify-content: space-between;
align-items: baseline;
line-height: 20px;
font-size: 14px;
font-weight: 500;
}
.edit-link { .edit-link {
padding-bottom: 14px; padding-bottom: 14px;
} }
@ -52,9 +67,6 @@ const control = usePrevNext()
align-items: center; align-items: center;
border: 0; border: 0;
padding: 10px 0; padding: 10px 0;
line-height: 20px;
font-size: 14px;
font-weight: 500;
color: var(--vp-c-brand); color: var(--vp-c-brand);
transition: color 0.25s; transition: color 0.25s;
} }

@ -0,0 +1,21 @@
<script setup lang="ts">
import { ref, onMounted, watchEffect } from 'vue'
import { useData } from 'vitepress'
const { theme, page } = useData()
const datetime = ref('')
onMounted(() => {
watchEffect(() => {
// locale string might be different based on end user
// and will lead to potential hydration mismatch if calculated at build time
datetime.value = new Date(page.value.lastUpdated!).toLocaleString(window.navigator.language)
})
})
</script>
<template>
<div>
{{ theme.lastUpdated ?? 'Edit this page' }}: {{ datetime }}
</div>
</template>

@ -23,6 +23,13 @@ export namespace DefaultTheme {
*/ */
editLink?: EditLink editLink?: EditLink
/**
* Show last updated time at the bottom of the page. Defaults to `false`.
* If given a string, it will be displayed as a prefix (default value:
* "Last Updated").
*/
lastUpdated?: string | boolean
/** /**
* The social links to be displayed at the end of the nav bar. Perfect for * The social links to be displayed at the end of the nav bar. Perfect for
* placing links to social services such as GitHub, Twitter, Facebook, etc. * placing links to social services such as GitHub, Twitter, Facebook, etc.

Loading…
Cancel
Save