Skip to content

Commit

Permalink
docs($plugin-last-updated): update
Browse files Browse the repository at this point in the history
  • Loading branch information
ulivz committed Nov 25, 2018
1 parent c059faa commit 8c6b069
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
17 changes: 14 additions & 3 deletions packages/docs/docs/plugin/official/plugin-last-updated.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,31 @@ module.exports = {

### transformer

- Type: `function`
- Type: `(timestamp: number, lang: string) => string`
- Default: `undefined`

By default, this plugin produces a 13-bit timestamp for each page, you can also pass in a transformer to convert it to any format that you want.

``` javascript
const timeago = require("timeago.js");
const moment = require('moment');

module.exports = {
plugins: [
[
'last-updated',
{ transformer: timeago.format }
{
transformer: (timestamp, lang) => {
moment.locale(lang)
return moment(timestamp).fromNow()
}
}
]
]
}
```

::: tip
If you are running in [i18n](../../guide/i18n.md) mode, you can also use the second argument `lang` to generate time strings for different languages.

Note that in VuePres, 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.
:::
17 changes: 14 additions & 3 deletions packages/docs/docs/zh/plugin/official/plugin-last-updated.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,31 @@ module.exports = {

### transformer

- 类型: `function`
- Type: `(timestamp: number, lang: string) => string`
- 默认值: `undefined`

默认情况下,本插件为每个页面生成一个 13 位的时间戳,你可以传入一个 transformer 将其转换为你想要的任何格式。

``` javascript
const timeago = require("timeago.js");
const moment = require('moment');

module.exports = {
plugins: [
[
'last-updated',
{ transformer: timeago.format }
{
transformer: (timestamp, lang) => {
moment.locale(lang)
return moment(timestamp).fromNow()
}
}
]
]
}
```

::: tip
如果你在 [i18n](../../guide/i18n.md) 模式下运行,你还可以使用第二个参数 `lang` 为不同语言生成时间字符串。

请注意,在VuePres中,我们遵循以下规范:[W3C > Language tags in HTML and XML](https://en.wikipedia.org/wiki/Language_localisation),因此 `zh-CN` 使用连字符(`-`)而不是下划线(`_`)。 请确保你使用的库遵循此规范,否则请自行转换。
:::

0 comments on commit 8c6b069

Please sign in to comment.