Skip to content

Commit 4921f99

Browse files
committedMay 4, 2018
feat: disable lastUpdated by default
1 parent d344043 commit 4921f99

File tree

3 files changed

+28
-8
lines changed

3 files changed

+28
-8
lines changed
 

‎docs/.vuepress/config.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@ module.exports = {
44
'/': {
55
lang: 'en-US',
66
title: 'VuePress',
7-
description: 'Vue-powered Static Site Generator',
8-
lastUpdated: 'Last Updated'
7+
description: 'Vue-powered Static Site Generator'
98
},
109
'/zh/': {
1110
lang: 'zh-CN',
1211
title: 'VuePress',
13-
description: 'Vue 驱动的静态网站生成器',
14-
lastUpdated: '上次更新'
12+
description: 'Vue 驱动的静态网站生成器'
1513
}
1614
},
1715
head: [
@@ -36,6 +34,7 @@ module.exports = {
3634
label: 'English',
3735
selectText: 'Languages',
3836
editLinkText: 'Edit this page on GitHub',
37+
lastUpdated: 'Last Updated',
3938
nav: [
4039
{
4140
text: 'Guide',
@@ -58,6 +57,7 @@ module.exports = {
5857
label: '简体中文',
5958
selectText: '选择语言',
6059
editLinkText: '在 GitHub 上编辑此页',
60+
lastUpdated: '上次更新',
6161
nav: [
6262
{
6363
text: '指南',

‎lib/default-theme/Page.vue

+13-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
</router-link> →
1919
</span>
2020
</p>
21-
<div class="last-updated">{{ $localeConfig.lastUpdated || 'Last Updated' }}: {{ lastUpdated }}</div>
21+
<div v-if="lastUpdated" class="last-updated">{{ lastUpdatedText }}: {{ lastUpdated }}</div>
2222
</div>
2323
<slot name="bottom"/>
2424
</div>
@@ -33,7 +33,18 @@ export default {
3333
props: ['sidebarItems'],
3434
computed: {
3535
lastUpdated () {
36-
return new Date(this.$page.lastUpdated).toLocaleString(this.$localeConfig.lang)
36+
if (this.$page.lastUpdated) {
37+
return new Date(this.$page.lastUpdated).toLocaleString(this.$lang)
38+
}
39+
},
40+
lastUpdatedText () {
41+
if (typeof this.$themeLocaleConfig.lastUpdated === 'string') {
42+
return this.$themeLocaleConfig.lastUpdated
43+
}
44+
if (typeof this.$site.themeConfig.lastUpdated === 'string') {
45+
return this.$site.themeConfig.lastUpdated
46+
}
47+
return 'Last Updated'
3748
},
3849
prev () {
3950
const prev = this.$page.frontmatter.prev

‎lib/prepare.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -181,15 +181,24 @@ async function resolveOptions (sourceDir) {
181181
// resolve pageFiles
182182
const pageFiles = sort(await globby(['**/*.md', '!.vuepress', '!node_modules'], { cwd: sourceDir }))
183183

184+
// resolve lastUpdated
185+
const shouldResolveLastUpdated = (
186+
themeConfig.lastUpdated ||
187+
Object.keys(siteConfig.locales && themeConfig.locales || {})
188+
.some(base => themeConfig.locales[base].lastUpdated)
189+
)
190+
184191
// resolve pagesData
185192
const pagesData = await Promise.all(pageFiles.map(async (file) => {
186193
const filepath = path.resolve(sourceDir, file)
187-
const lastUpdated = getGitLastUpdatedTimeStamp(filepath)
188194
const data = {
189-
lastUpdated,
190195
path: fileToPath(file)
191196
}
192197

198+
if (shouldResolveLastUpdated) {
199+
data.lastUpdated = getGitLastUpdatedTimeStamp(filepath)
200+
}
201+
193202
// extract yaml frontmatter
194203
const content = await fs.readFile(filepath, 'utf-8')
195204
const frontmatter = parseFrontmatter(content)

0 commit comments

Comments
 (0)