lorisleiva / vuepress-plugin-seo

🔌 Generate SEO friendly meta header for every page
MIT License
106 stars 7 forks source link

Build fail with zh locale #9

Open ahopkins opened 3 years ago

ahopkins commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

Opened https://github.com/vuejs/vuepress/pull/2843, hoping this will help.

Kocal commented 3 years ago

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',
    ],
    // ...
    }
  2. 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>


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](https://user-images.githubusercontent.com/2103975/117198156-f044f100-ade8-11eb-81b8-71ee68aed374.png)
- with a french page (`fr`) : 
![image](https://user-images.githubusercontent.com/2103975/117198171-f76bff00-ade8-11eb-852f-c8a94419c8da.png)
rodber commented 1 year ago

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")