From c059faa6fd19ee63ab8a9515c1b0cf349b805697 Mon Sep 17 00:00:00 2001 From: ULIVZ <472590061@qq.com> Date: Mon, 26 Nov 2018 01:31:35 +0800 Subject: [PATCH] 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 --- packages/@vuepress/plugin-last-updated/index.js | 9 ++++++++- packages/@vuepress/theme-default/components/Page.vue | 4 +--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/packages/@vuepress/plugin-last-updated/index.js b/packages/@vuepress/plugin-last-updated/index.js index d6fa880b09..cf307083ad 100644 --- a/packages/@vuepress/plugin-last-updated/index.js +++ b/packages/@vuepress/plugin-last-updated/index.js @@ -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 { diff --git a/packages/@vuepress/theme-default/components/Page.vue b/packages/@vuepress/theme-default/components/Page.vue index 19b90491fc..e346021023 100644 --- a/packages/@vuepress/theme-default/components/Page.vue +++ b/packages/@vuepress/theme-default/components/Page.vue @@ -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 () {