From 369c31520b48131d1c8dcff6dcc95f2699ed68bb Mon Sep 17 00:00:00 2001 From: Ramona Date: Tue, 25 Feb 2020 11:44:44 +0100 Subject: [PATCH] feat($plugin-last-updated): add dateOptions to options (#2192) --- .../@vuepress/plugin-last-updated/index.js | 8 +++---- .../plugin/official/plugin-last-updated.md | 23 +++++++++++++++++++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/packages/@vuepress/plugin-last-updated/index.js b/packages/@vuepress/plugin-last-updated/index.js index c845e6a047..72e48094d5 100644 --- a/packages/@vuepress/plugin-last-updated/index.js +++ b/packages/@vuepress/plugin-last-updated/index.js @@ -3,20 +3,20 @@ const spawn = require('cross-spawn') module.exports = (options = {}, context) => ({ extendPageData ($page) { - const { transformer } = options + const { transformer, dateOptions } = options const timestamp = getGitLastUpdatedTimeStamp($page._filePath) const $lang = $page._computed.$lang if (timestamp) { const lastUpdated = typeof transformer === 'function' ? transformer(timestamp, $lang) - : defaultTransformer(timestamp, $lang) + : defaultTransformer(timestamp, $lang, dateOptions) $page.lastUpdated = lastUpdated } } }) -function defaultTransformer (timestamp, lang) { - return new Date(timestamp).toLocaleString(lang) +function defaultTransformer (timestamp, lang, dateOptions) { + return new Date(timestamp).toLocaleString(lang, dateOptions) } function getGitLastUpdatedTimeStamp (filePath) { diff --git a/packages/docs/docs/plugin/official/plugin-last-updated.md b/packages/docs/docs/plugin/official/plugin-last-updated.md index e019611039..b7bd10b5b4 100644 --- a/packages/docs/docs/plugin/official/plugin-last-updated.md +++ b/packages/docs/docs/plugin/official/plugin-last-updated.md @@ -55,3 +55,26 @@ If you are running in [i18n](../../guide/i18n.md) mode, you can also use the sec Note that in VuePress, we follow this spec: [W3C > Language tags in HTML and XML](https://en.wikipedia.org/wiki/Language_localisation), so `en-US` uses hyphens (`-`) instead of underscores (`_`). Please make sure that the library you are using follows this spec, otherwise please convert it yourself. ::: + +### dateOptions + +- Type: `object` +- Default: `undefined` + +You can also pass in an options object to customize the timestamp output. For more properties check [`Date.prototype.toLocaleString()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleString) options argument + +```javascript + +module.exports = { + plugins: [ + [ + '@vuepress/last-updated', + { + dateOptions:{ + hours12: false + } + } + ] + ] +} +```