Skip to content

Commit

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

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.

e.g.

``` javascript
const moment = require('moment');

module.exports = {
plugins: [
[
'last-updated',
{
'@vuepress/last-updated',
{
transformer: (timestamp, lang) => {
// Don't forget to install moment yourself
const moment = require('moment')
moment.locale(lang)
return moment(timestamp).fromNow()
}
Expand Down
8 changes: 6 additions & 2 deletions packages/docs/docs/zh/plugin/official/plugin-last-updated.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,19 @@ module.exports = {

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

例子:

``` javascript
const moment = require('moment');

module.exports = {
plugins: [
[
'last-updated',
{
'@vuepress/last-updated',
{
transformer: (timestamp, lang) => {
// 不要忘了安装 moment
const moment = require('moment')
moment.locale(lang)
return moment(timestamp).fromNow()
}
Expand Down

10 comments on commit c15bdfc

@chenweigao
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, could you please help with that how can I pass in a transformer in my code? thank you

@chenweigao
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

or how should I set the timestamp, when I upgrade to alpha.24, my last updated could not show as the formatted style

@ulivz
Copy link
Member Author

@ulivz ulivz commented on c15bdfc Nov 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy the sample of the docs:

module.exports = {
  plugins: [
    [ 
      '@vuepress/last-updated',
      {
        transformer: (timestamp, lang) => {
          // Don't forget to install moment yourself
          const moment = require('moment')
          moment.locale(lang)
          return moment(timestamp).fromNow()
        }
      }
    ]
  ]
}

@chenweigao
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ulivz thank you~!

@chenweigao
Copy link

@chenweigao chenweigao commented on c15bdfc Nov 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ulivz sorry for troubling you again, my bug is shown as:

Last Updated: Invalid date

and I have done these things:

  • yarn add moment -D
  • update the last-update plugin
  • in enhanceAPP.js add Vue.require moment
  • in config.js copy your code
  • add the plugin i18n-ui

but it was unable to show the time, there are some warning:

Deprecation warning: value provided is not in a recognized RFC2822 or ISO format. moment construction falls back to js Dat
e(), which is not reliable across all browsers and versions. Non RFC2822/ISO date formats are discouraged and will be remo
ved in an upcoming major release. Please refer to http://momentjs.com/guides/#/warnings/js-date/ for more info.
Arguments:
[0] _isAMomentObject: true, _isUTC: false, _useUTC: false, _l: undefined, _i: timestamp, _f: undefined, _strict: undefined
, _locale: [object Object]
Error
    at Function.createFromInputFallback (C:\Users\nerche\Documents\_code\vueblog\node_modules\moment\moment.js:320:98)
    at configFromString (C:\Users\nerche\Documents\_code\vueblog\node_modules\moment\moment.js:2368:15)
    at configFromInput (C:\Users\nerche\Documents\_code\vueblog\node_modules\moment\moment.js:2594:13)
    at prepareConfig (C:\Users\nerche\Documents\_code\vueblog\node_modules\moment\moment.js:2577:13)
    at createFromConfig (C:\Users\nerche\Documents\_code\vueblog\node_modules\moment\moment.js:2544:44)
    at createLocalOrUTC (C:\Users\nerche\Documents\_code\vueblog\node_modules\moment\moment.js:2631:16)
    at createLocal (C:\Users\nerche\Documents\_code\vueblog\node_modules\moment\moment.js:2635:16)
    at hooks (C:\Users\nerche\Documents\_code\vueblog\node_modules\moment\moment.js:12:29)
    at transformer (C:\Users\nerche\Documents\_code\vueblog\docs\.vuepress\config.js:26:18)
    at extendPageData (C:\Users\nerche\Documents\_code\vueblog\node_modules\@vuepress\plugin-last-updated\index.js:10:11)

could you help me find where the problem lies in?
thank you again.

@ulivz
Copy link
Member Author

@ulivz ulivz commented on c15bdfc Nov 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can create an issue with an reproduction repo...

BTW, why did you require moment at client side?

@chenweigao
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ulivz sry for a meeting delayed the reply, see you at issue next day, good night~!

@chenweigao
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ulivz I followed your advice and fixed my bug, would you mind me helping you with the docs?

@ulivz
Copy link
Member Author

@ulivz ulivz commented on c15bdfc Nov 27, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, but are you sure that the docs need to be updated??? Please check out the latest documentation - -

@chenweigao
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

233333333

Please sign in to comment.