Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions packages/@vuepress/plugin-last-updated/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
23 changes: 23 additions & 0 deletions packages/docs/docs/plugin/official/plugin-last-updated.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
]
]
}
```