Skip to content

Commit 8c6b069

Browse files
committed
docs($plugin-last-updated): update
1 parent c059faa commit 8c6b069

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

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

+14-3
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,31 @@ module.exports = {
2323

2424
### transformer
2525

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

2929
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.
3030

3131
``` javascript
32-
const timeago = require("timeago.js");
32+
const moment = require('moment');
3333

3434
module.exports = {
3535
plugins: [
3636
[
3737
'last-updated',
38-
{ transformer: timeago.format }
38+
{
39+
transformer: (timestamp, lang) => {
40+
moment.locale(lang)
41+
return moment(timestamp).fromNow()
42+
}
43+
}
3944
]
4045
]
4146
}
4247
```
48+
49+
::: tip
50+
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.
51+
52+
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.
53+
:::

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

+14-3
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,31 @@ module.exports = {
2323

2424
### transformer
2525

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

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

3131
``` javascript
32-
const timeago = require("timeago.js");
32+
const moment = require('moment');
3333

3434
module.exports = {
3535
plugins: [
3636
[
3737
'last-updated',
38-
{ transformer: timeago.format }
38+
{
39+
transformer: (timestamp, lang) => {
40+
moment.locale(lang)
41+
return moment(timestamp).fromNow()
42+
}
43+
}
3944
]
4045
]
4146
}
4247
```
48+
49+
::: tip
50+
如果你在 [i18n](../../guide/i18n.md) 模式下运行,你还可以使用第二个参数 `lang` 为不同语言生成时间字符串。
51+
52+
请注意,在VuePres中,我们遵循以下规范:[W3C > Language tags in HTML and XML](https://en.wikipedia.org/wiki/Language_localisation),因此 `zh-CN` 使用连字符(`-`)而不是下划线(`_`)。 请确保你使用的库遵循此规范,否则请自行转换。
53+
:::

0 commit comments

Comments
 (0)