Skip to content

Commit

Permalink
fix($theme-default): shouldn't transform date string at client side (c…
Browse files Browse the repository at this point in the history
…lose: #1035)

Move the transformation to $plugin-last-updated, BTW, expose `lang` as the 2nd argument
  • Loading branch information
ulivz committed Nov 25, 2018
1 parent d338468 commit c059faa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
9 changes: 8 additions & 1 deletion packages/@vuepress/plugin-last-updated/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@ module.exports = (options = {}, context) => ({
extendPageData ($page) {
const { transformer } = options
const timestamp = getGitLastUpdatedTimeStamp($page._filePath)
const $lang = $page._computed.$lang
if (timestamp) {
const lastUpdated = typeof transformer === 'function' ? transformer(timestamp) : timestamp
const lastUpdated = typeof transformer === 'function'
? transformer(timestamp, $lang)
: defaultTransformer(timestamp, $lang)
$page.lastUpdated = lastUpdated
}
}
})

function defaultTransformer (timestamp, lang) {
return new Date(timestamp).toLocaleString(lang)
}

function getGitLastUpdatedTimeStamp (filePath) {
let lastUpdated
try {
Expand Down
4 changes: 1 addition & 3 deletions packages/@vuepress/theme-default/components/Page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ export default {
},
lastUpdated () {
if (this.$page.lastUpdated) {
return new Date(this.$page.lastUpdated).toLocaleString(this.$lang)
}
return this.$page.lastUpdated
},
lastUpdatedText () {
Expand Down

0 comments on commit c059faa

Please sign in to comment.