How to avoid update time error when deploy hexo blog using CI CD

A long time ago, I have found my post update time will be changed if I delete and regenerate the file and I do not take care of this small problem. And now I have found all my post was add the modified tag, whose time is the same as time I compile. Today I find the reason and solution finally.

Reason

Hexo uses file modify date as update time by default if you do not clarify this parameter in front-matter of post. CI CD in Gitea always delete and recreate file so file’s modify time changed frequently. So we can change the default settings and clarify this parameter manually to avoid this problem.

Solution

Edit your _config.yml file.

1
2
## updated_option supports 'mtime', 'date', 'empty'
updated_option: 'date'

Then hexo won’t view modify time of file as post update time if do not clarify it. And you need to update hexo no earlier than 5.0 following my post before.

Edit your /scaffolds/post.md file.

1
2
3
4
5
6
7
8
9
10
---
title: {{ title }}
date: {{ date }}
updated: {{ date }}
comments: false
categories:
tags:
excerpt:
lang: en
---

Then you will generate updated time parameter automatically when create new post.

Have fun with your new version hexo!

Reference

  1. https://github.com/YunYouJun/hexo-theme-yun/issues/60
  2. https://hexo.io/zh-cn/docs/configuration.html
  3. https://shyblog.world/posts/4257638701/
  4. https://sqiang.net/post/2792803495.html