Skip to content

Commit

Permalink
feat: add "last updated" feature
Browse files Browse the repository at this point in the history
  • Loading branch information
kiaking committed Nov 24, 2020
1 parent fdc7a50 commit 40d204b
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 9 deletions.
7 changes: 1 addition & 6 deletions src/client/theme-default/components/EditLink.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,9 @@ export default defineComponent({
</script>

<style scoped>
.edit-link {
padding-top: 1rem;
padding-bottom: 1rem;
overflow: auto;
}
.link {
display: inline-block;
font-size: 1rem;
font-weight: 500;
color: var(--c-text-light);
}
Expand Down
67 changes: 67 additions & 0 deletions src/client/theme-default/components/LastUpdated.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<template>
<p v-if="hasLastUpdated" class="last-updated">
<span class="prefix">{{ prefix }}:</span>
<span class="datetime">{{ datetime }}</span>
</p>
</template>

<script lang="ts">
import { defineComponent, computed } from 'vue'
import { useSiteDataByRoute, usePageData } from 'vitepress'
export default defineComponent({
setup() {
const site = useSiteDataByRoute()
const page = usePageData()
const hasLastUpdated = computed(() => {
const lu = site.value.themeConfig.lastUpdated
return lu !== undefined && lu !== false
})
const prefix = computed(() => {
const p = site.value.themeConfig.lastUpdated
return p === true ? 'Last Updated' : p
})
const datetime = computed(() => {
return new Date(page.value.lastUpdated).toLocaleString('en-US')
})
return {
hasLastUpdated,
prefix,
datetime
}
}
})
</script>

<style scoped>
.last-updated {
display: inline-block;
margin: 0;
line-height: 1.4;
font-size: .9rem;
color: var(--c-text-light);
}
@media (min-width: 960px) {
.last-updated {
font-size: 1rem;
}
}
.prefix {
display: inline-block;
font-weight: 500;
}
.datetime {
display: inline-block;
margin-left: 6px;
font-weight: 400;
}
</style>
7 changes: 4 additions & 3 deletions src/client/theme-default/components/Page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
<Content />
</div>

<EditLink />
<PageFooter />

<NextAndPrevLinks />

<slot name="bottom" />
Expand All @@ -15,12 +16,12 @@

<script lang="ts">
import { defineComponent } from 'vue'
import EditLink from './EditLink.vue'
import PageFooter from './PageFooter.vue'
import NextAndPrevLinks from './NextAndPrevLinks.vue'
export default defineComponent({
components: {
EditLink,
PageFooter,
NextAndPrevLinks
}
})
Expand Down
49 changes: 49 additions & 0 deletions src/client/theme-default/components/PageFooter.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<template>
<footer class="page-footer">
<div class="edit">
<EditLink />
</div>
<div class="updated">
<LastUpdated />
</div>
</footer>
</template>

<script lang="ts">
import { defineComponent } from 'vue'
import EditLink from './EditLink.vue'
import LastUpdated from './LastUpdated.vue'
export default defineComponent({
components: {
EditLink,
LastUpdated
}
})
</script>

<style scoped>
.page-footer {
padding-top: 1rem;
padding-bottom: 1rem;
overflow: auto;
}
@media (min-width: 960px) {
.page-footer {
display: flex;
justify-content: space-between;
align-items: center;
}
}
.updated {
padding-top: 4px;
}
@media (min-width: 960px) {
.updated {
padding-top: 0;
}
}
</style>
6 changes: 6 additions & 0 deletions src/client/theme-default/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,13 @@ export namespace DefaultTheme {
*/
editLinkText?: string

/**
* 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

prevLink?: boolean
nextLink?: boolean
}
Expand Down

0 comments on commit 40d204b

Please sign in to comment.