Skip to content

Commit

Permalink
fix(build): respect frontmatter.lastUpdated for pageData.lastUpdated …
Browse files Browse the repository at this point in the history
…and sitemap generation

closes #3931
  • Loading branch information
brc-dd committed Jun 9, 2024
1 parent 99053ba commit 7fcf462
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 17 deletions.
42 changes: 29 additions & 13 deletions src/client/theme-default/components/VPDocFooter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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('')
Expand Down
7 changes: 7 additions & 0 deletions src/node/build/generateSitemap.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import fs from 'fs-extra'
import matter from 'gray-matter'
import path from 'path'
import {
SitemapStream,
Expand All @@ -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
}

Expand Down
8 changes: 6 additions & 2 deletions src/node/markdownToVue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 7fcf462

Please sign in to comment.