Skip to content

Commit 369c315

Browse files
authored
feat($plugin-last-updated): add dateOptions to options (#2192)
1 parent a9759c0 commit 369c315

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,20 @@ const spawn = require('cross-spawn')
33

44
module.exports = (options = {}, context) => ({
55
extendPageData ($page) {
6-
const { transformer } = options
6+
const { transformer, dateOptions } = options
77
const timestamp = getGitLastUpdatedTimeStamp($page._filePath)
88
const $lang = $page._computed.$lang
99
if (timestamp) {
1010
const lastUpdated = typeof transformer === 'function'
1111
? transformer(timestamp, $lang)
12-
: defaultTransformer(timestamp, $lang)
12+
: defaultTransformer(timestamp, $lang, dateOptions)
1313
$page.lastUpdated = lastUpdated
1414
}
1515
}
1616
})
1717

18-
function defaultTransformer (timestamp, lang) {
19-
return new Date(timestamp).toLocaleString(lang)
18+
function defaultTransformer (timestamp, lang, dateOptions) {
19+
return new Date(timestamp).toLocaleString(lang, dateOptions)
2020
}
2121

2222
function getGitLastUpdatedTimeStamp (filePath) {

packages/docs/docs/plugin/official/plugin-last-updated.md

+23
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,26 @@ If you are running in [i18n](../../guide/i18n.md) mode, you can also use the sec
5555

5656
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.
5757
:::
58+
59+
### dateOptions
60+
61+
- Type: `object`
62+
- Default: `undefined`
63+
64+
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
65+
66+
```javascript
67+
68+
module.exports = {
69+
plugins: [
70+
[
71+
'@vuepress/last-updated',
72+
{
73+
dateOptions:{
74+
hours12: false
75+
}
76+
}
77+
]
78+
]
79+
}
80+
```

0 commit comments

Comments
 (0)