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

Build fail with zh locale #9

Open
ahopkins opened this issue Mar 21, 2021 · 4 comments
Open

Build fail with zh locale #9

ahopkins opened this issue Mar 21, 2021 · 4 comments

Comments

@ahopkins
Copy link

See here: https://github.com/sanic-org/sanic-guide/runs/2158958551?check_suite_focus=true

RangeError: Invalid time value
    at Date.toISOString (<anonymous>)
    at Object.modifiedAt (/home/runner/work/sanic-guide/sanic-guide/node_modules/vuepress-plugin-seo/index.js:64:77)
Error: [vuepress-plugin-seo] execute extendPageData failed.
    at extendPageData (/home/runner/work/sanic-guide/sanic-guide/node_modules/vuepress-plugin-seo/index.js:27:37)
    at /home/runner/work/sanic-guide/sanic-guide/node_modules/@vuepress/core/lib/node/Page.js:296:19
    at /home/runner/work/sanic-guide/sanic-guide/node_modules/@vuepress/core/lib/node/Page.js:293:19
    at Array.map (<anonymous>)
    at Array.map (<anonymous>)
    at Page.enhance (/home/runner/work/sanic-guide/sanic-guide/node_modules/@vuepress/core/lib/node/Page.js:290:17)
    at Page.enhance (/home/runner/work/sanic-guide/sanic-guide/node_modules/@vuepress/core/lib/node/Page.js:290:17)
    at Page.process (/home/runner/work/sanic-guide/sanic-guide/node_modules/@vuepress/core/lib/node/Page.js:148:16)
    at Page.process (/home/runner/work/sanic-guide/sanic-guide/node_modules/@vuepress/core/lib/node/Page.js:148:16)
    at async App.addPage (/home/runner/work/sanic-guide/sanic-guide/node_modules/@vuepress/core/lib/node/App.js:354:5)
    at async App.addPage (/home/runner/work/sanic-guide/sanic-guide/node_modules/@vuepress/core/lib/node/App.js:354:5)
    at async /home/runner/work/sanic-guide/sanic-guide/node_modules/@vuepress/core/lib/node/App.js:339:7
    at async Promise.all (index 56)
    at async App.resolvePages (/home/runner/work/sanic-guide/sanic-guide/node_modules/@vuepress/core/lib/node/App.js:337:5)
    at async App.process (/home/runner/work/sanic-guide/sanic-guide/node_modules/@vuepress/core/lib/node/App.js:115:5)
    at async build (/home/runner/work/sanic-guide/sanic-guide/node_modules/@vuepress/core/lib/index.js:26:3)
    at async /home/runner/work/sanic-guide/sanic-guide/node_modules/@vuepress/core/lib/node/App.js:339:7
    at async Promise.all (index 56)
    at async App.resolvePages (/home/runner/work/sanic-guide/sanic-guide/node_modules/@vuepress/core/lib/node/App.js:337:5)
    at async App.process (/home/runner/work/sanic-guide/sanic-guide/node_modules/@vuepress/core/lib/node/App.js:115:5)
    at async build (/home/runner/work/sanic-guide/sanic-guide/node_modules/@vuepress/core/lib/index.js:26:3)
RangeError: Invalid time value
    at Date.toISOString (<anonymous>)
    at Object.modifiedAt (/home/runner/work/sanic-guide/sanic-guide/node_modules/vuepress-plugin-seo/index.js:64:77)
    at extendPageData (/home/runner/work/sanic-guide/sanic-guide/node_modules/vuepress-plugin-seo/index.js:27:37)
    at /home/runner/work/sanic-guide/sanic-guide/node_modules/@vuepress/core/lib/node/Page.js:293:19
    at Array.map (<anonymous>)
    at Page.enhance (/home/runner/work/sanic-guide/sanic-guide/node_modules/@vuepress/core/lib/node/Page.js:290:17)
    at Page.process (/home/runner/work/sanic-guide/sanic-guide/node_modules/@vuepress/core/lib/node/Page.js:148:16)
    at async App.addPage (/home/runner/work/sanic-guide/sanic-guide/node_modules/@vuepress/core/lib/node/App.js:354:5)
    at async /home/runner/work/sanic-guide/sanic-guide/node_modules/@vuepress/core/lib/node/App.js:339:7
    at async Promise.all (index 57)

It seems like I am running into build issues, and I think this is related to the locale. I am build fine locally, but our CI and other contributors in China seem to be getting this error.

Any thoughts?

@Kocal
Copy link

Kocal commented May 5, 2021

Funny, I also got the same error but with fr lang.

The seo plugin is based on $page.lastUpdated (added by @vuepress/plugin-last-updated) that can be a localized date:
image

And when the seo plugin encounters a date that can't be parsed through new Date(), it fails.

Ideally, it would be great to have a new key $page.lastUpdatedTimestamp with the timestamp value. This way, the seo plugin could easily use it without any issue.

@Kocal
Copy link

Kocal commented May 5, 2021

Opened vuejs/vuepress#2843, hoping this will help.

@Kocal
Copy link

Kocal commented May 5, 2021

As a workaround, you can do this:

  1. Update your Vuepress theme configuration, configure the plugin @vuepress/theme-default to always returns a timestamp:
// .vuepress/theme/index.js
module.exports = {
  extend: '@vuepress/theme-default',
  plugins: [
    ['@vuepress/last-updated', {
      transformer(timestamp) {
        return timestamp;
      }
    }],
    'seo',
  ],
  // ...
}
  1. Create a new file theme/components/PageEdit.vue, which will extends the original component but override lastUpdate computed:
<template>
  <footer class="page-edit">
    <div
        v-if="editLink"
        class="edit-link"
    >
      <a
          :href="editLink"
          target="_blank"
          rel="noopener noreferrer"
      >{{ editLinkText }}</a>
      <OutboundLink />
    </div>

    <div
        v-if="lastUpdated"
        class="last-updated"
    >
      <span class="prefix">{{ lastUpdatedText }}:</span>
      <time class="time">{{ lastUpdated }}</time>
    </div>
  </footer>
</template>

<script>
import PageEdit from '@parent-theme/components/PageEdit.vue';

export default {
  extends: PageEdit,
  computed: {
    lastUpdated() {
      return new Date(this.$page.lastUpdated).toLocaleString(this.$lang)
    }
  }
};
</script>

This way, you don't have any issues anymore from the seo plugin, and the last updated date is still formatted correctly:

  • with an english page (en-US):
    image
  • with a french page (fr) :
    image

@rodber
Copy link

rodber commented Jul 15, 2022

Also affects es, es-ES and es-CL.

To fix this you can add the following property in your themeConfig:

themeConfig.sitemap.dateFormatter: (time) => new Date(time).toLocaleString("es-CL")

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

3 participants