fix(build): respect frontmatter.lastUpdated for pageData.lastUpdated and sitemap generation

closes #3931
pull/3291/head
Divyansh Singh 5 months ago
parent 99053baea7
commit 7fcf462eb8

@ -11,15 +11,17 @@ const { theme, page, frontmatter } = useData()
const editLink = useEditLink()
const control = usePrevNext()
const hasEditLink = computed(() => {
return theme.value.editLink && frontmatter.value.editLink !== false
})
const hasLastUpdated = computed(() => {
return page.value.lastUpdated && frontmatter.value.lastUpdated !== false
})
const showFooter = computed(() => {
return hasEditLink.value || hasLastUpdated.value || control.value.prev || control.value.next
})
const hasEditLink = computed(
() => theme.value.editLink && frontmatter.value.editLink !== false
)
const hasLastUpdated = computed(() => page.value.lastUpdated)
const showFooter = computed(
() =>
hasEditLink.value ||
hasLastUpdated.value ||
control.value.prev ||
control.value.next
)
</script>
<template>
@ -47,14 +49,28 @@ const showFooter = computed(() => {
<span class="visually-hidden" id="doc-footer-aria-label">Pager</span>
<div class="pager">
<VPLink v-if="control.prev?.link" class="pager-link prev" :href="control.prev.link">
<span class="desc" v-html="theme.docFooter?.prev || 'Previous page'"></span>
<VPLink
v-if="control.prev?.link"
class="pager-link prev"
:href="control.prev.link"
>
<span
class="desc"
v-html="theme.docFooter?.prev || 'Previous page'"
></span>
<span class="title" v-html="control.prev.text"></span>
</VPLink>
</div>
<div class="pager">
<VPLink v-if="control.next?.link" class="pager-link next" :href="control.next.link">
<span class="desc" v-html="theme.docFooter?.next || 'Next page'"></span>
<VPLink
v-if="control.next?.link"
class="pager-link next"
:href="control.next.link"
>
<span
class="desc"
v-html="theme.docFooter?.next || 'Next page'"
></span>
<span class="title" v-html="control.next.text"></span>
</VPLink>
</div>

@ -2,10 +2,10 @@
import { ref, computed, watchEffect, onMounted } from 'vue'
import { useData } from '../composables/data'
const { theme, page, frontmatter, lang } = useData()
const { theme, page, lang } = useData()
const date = computed(
() => new Date(frontmatter.value.lastUpdated ?? page.value.lastUpdated)
() => new Date(page.value.lastUpdated!)
)
const isoDatetime = computed(() => date.value.toISOString())
const datetime = ref('')

@ -1,4 +1,5 @@
import fs from 'fs-extra'
import matter from 'gray-matter'
import path from 'path'
import {
SitemapStream,
@ -22,6 +23,12 @@ export async function generateSitemap(siteConfig: SiteConfig) {
file = siteConfig.rewrites.inv[file] || file
file = path.join(siteConfig.srcDir, file)
if (!fs.existsSync(file)) return undefined
const { data } = matter.read(file)
if (data.lastUpdated === false) return undefined
if (data.lastUpdated instanceof Date) return +data.lastUpdated
return (await getGitTimestamp(file)) || undefined
}

@ -185,8 +185,12 @@ export async function createMarkdownToVueRenderFn(
filePath: slash(path.relative(srcDir, fileOrig))
}
if (includeLastUpdatedData) {
pageData.lastUpdated = await getGitTimestamp(fileOrig)
if (includeLastUpdatedData && frontmatter.lastUpdated !== false) {
if (frontmatter.lastUpdated instanceof Date) {
pageData.lastUpdated = +frontmatter.lastUpdated
} else {
pageData.lastUpdated = await getGitTimestamp(fileOrig)
}
}
if (siteConfig?.transformPageData) {

Loading…
Cancel
Save