Skip to content

Commit c059faa

Browse files
committed
fix($theme-default): shouldn't transform date string at client side (close: #1035)
Move the transformation to $plugin-last-updated, BTW, expose `lang` as the 2nd argument
1 parent d338468 commit c059faa

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

packages/@vuepress/plugin-last-updated/index.js

+8-1
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,20 @@ module.exports = (options = {}, context) => ({
44
extendPageData ($page) {
55
const { transformer } = options
66
const timestamp = getGitLastUpdatedTimeStamp($page._filePath)
7+
const $lang = $page._computed.$lang
78
if (timestamp) {
8-
const lastUpdated = typeof transformer === 'function' ? transformer(timestamp) : timestamp
9+
const lastUpdated = typeof transformer === 'function'
10+
? transformer(timestamp, $lang)
11+
: defaultTransformer(timestamp, $lang)
912
$page.lastUpdated = lastUpdated
1013
}
1114
}
1215
})
1316

17+
function defaultTransformer (timestamp, lang) {
18+
return new Date(timestamp).toLocaleString(lang)
19+
}
20+
1421
function getGitLastUpdatedTimeStamp (filePath) {
1522
let lastUpdated
1623
try {

packages/@vuepress/theme-default/components/Page.vue

+1-3
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,7 @@ export default {
7373
},
7474
7575
lastUpdated () {
76-
if (this.$page.lastUpdated) {
77-
return new Date(this.$page.lastUpdated).toLocaleString(this.$lang)
78-
}
76+
return this.$page.lastUpdated
7977
},
8078
8179
lastUpdatedText () {

0 commit comments

Comments
 (0)