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

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

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

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

@ -1,4 +1,5 @@
import fs from 'fs-extra' import fs from 'fs-extra'
import matter from 'gray-matter'
import path from 'path' import path from 'path'
import { import {
SitemapStream, SitemapStream,
@ -22,6 +23,12 @@ export async function generateSitemap(siteConfig: SiteConfig) {
file = siteConfig.rewrites.inv[file] || file file = siteConfig.rewrites.inv[file] || file
file = path.join(siteConfig.srcDir, 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 return (await getGitTimestamp(file)) || undefined
} }

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

Loading…
Cancel
Save