Hexo Generate Wrong Permalinks Date

After Deploy Hexo From Private Repository to GitHub Pages, we encounter many issues: GitHub Checkout Action Preserve File Modification Time, and now some posts' permalinks date may shift one day. For instance, assume the original markdown date is 2020-07-13 00:50:05, the generated permalinks date becomes 2020/07/12. Since the permalinks changed, search engines will regard these posts are not found which impact the SEO performance.

Cosidering that the issue doesn't happen for all posts but for posts that wrote between 0-8am, it's likely that the root cause is timezone setting.

Read the official document # Permalinks but found no clue. Then we found related discussion .

Root cause: the time zone of _config.yml and the timezone setting of the machine are inconsistent.

I tried two solutions:

  • Delete _config.yml timezone setting timezone: Asia/Shanghai. However, all the posts' createtime and modification time are shifts for 8 hours. It doesn't work.
  • Set the GitHub Actions machine's timezone the same as the _config.yml timezone setting. It works!

The latter is the best solution, suggest to keep the deploy machine's configuration exactly the same as your local machine.

Add a new step Set Timezone after Restore Timestamps in .github/workflows/main.yml, use timedatectl to set timezone and output:

- name: Restore Timestamps
  uses: chetan/git-restore-mtime-action@v1

- name: Set Timezone
  run: |
    sudo timedatectl set-timezone Asia/Shanghai

- name: Prepare Node env
  uses: actions/setup-node@v3

Now it works!