Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

last-updated transfomer ignored after hydration #1035

Closed
1 task done
psi-4ward opened this issue Nov 22, 2018 · 3 comments
Closed
1 task done

last-updated transfomer ignored after hydration #1035

psi-4ward opened this issue Nov 22, 2018 · 3 comments

Comments

@psi-4ward
Copy link
Contributor

  • I confirm that this is a issue rather than a question.

Bug report

last-updated transfomer ignored after hydration

Version

^1.0.0-alpha.23

Steps to reproduce

config.js

plugins: {
    '@vuepress/last-updated': {
      transformer: tstamp => new Date(tstamp)
        .toLocaleString('de', {
          weekday: 'long',
          year: 'numeric',
          month: 'long',
          day: 'numeric',
          minute: '2-digit',
          hour: '2-digit'
        })
    },

if I debug the return value of the transfomer callback is a correct german local string.

The state of the <v-XXX> (the Component within <Content>) holds $page.lastUpdated: "Mittwoch, 21. November 2018, 22:17"
but the shows Last Updated: 11/21/2018, 10:17:00 PM

What is expected?

It should show the string from the transformer.

Other relevant information

  • Your OS: Arch Linux
  • Node.js version: 10.12
  • Browser version: Chrome 70
  • Is this a global or local install? local
  • Which package manager did you use for the install? npm
@ulivz
Copy link
Member

ulivz commented Nov 25, 2018

But when I copied your config to test, I got a Invalid Date.

I recommend you to use a professional date transformer instead of the native Date API, since it would have Inconsistent performance on different platforms.

Feel free to continue if you can provide a valid repro.

@ulivz ulivz closed this as completed Nov 25, 2018
@psi-4ward
Copy link
Contributor Author

psi-4ward commented Nov 25, 2018

Read the source: https://github.com/vuejs/vuepress/blob/master/packages/%40vuepress/theme-default/components/Page.vue#L77

It alrady uses toLocaleString without the plugin and takes the locale from the config.js locales

so translating a single language page to German:

  locales: {
    "/": {
      lang: "de-DE"
    }
  },

ulivz added a commit that referenced this issue Nov 25, 2018
…lose: #1035)

Move the transformation to $plugin-last-updated, BTW, expose `lang` as the 2nd argument
@ulivz
Copy link
Member

ulivz commented Nov 25, 2018

Cool, thanks for providing more information, it's truly a problem and the default date transform should be moved the the last-updated plugin. Fixed at c059faa and updated docs at 8c6b069

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants