Recently, after updating the article and using Travis CI for automatic deployment, it was discovered that the publication time of the article changed to the update time. After considering this issue, it is temporarily believed that the problem lies in the Travis CI automatic deployment, because the time is consistent with the deployment time after each automatic deployment.
Hypothesis Verification#
Step 1: Deploy using traditional hexo g and hexo d methods#
After deployment, it was found that the publication time and update time of the article changed. The publication time was the time when Travis CI automatic deployment was established, while the update time was the time after the traditional deployment. Therefore, it was determined that the problem occurred in the Travis CI automatic deployment.
Step 2: Check Travis CI automatic deployment file#
Open the Travis CI automatic deployment file .travis.yml
to view:
language: node_js
node_js: stable
cache:
directories:
- node_modules
before_install:
- export TZ='Asia/Shanghai' # Change time zone
- npm install hexo-cli -g
install:
- npm install
- npm install hexo-deployer-git --save
script:
- hexo clean
- hexo generate
after_script:
- cd ./public
- git init
- git config user.name "xuezheng-wei"
- git config user.email "[email protected]"
- git add .
- git commit -m "Travis CI Auto Updated"
- git push --force --quiet "https://${GH_TOKEN}@${GH_REF}" master:master
branches:
only:
- hexo
env:
global:
- GH_REF: github.com/xuezheng-wei/xuezheng-wei.github.io.git
It was found that after executing hexo generate, it does not directly execute hexo deploy, but switches to the hexo branch public directory and forcefully submits the updated files to the master branch. Therefore, it may not be able to distinguish between the publication time and the update time.
Step 3: Solution#
(1) Add hexo deploy in the .travis.yml
file so that it can be executed during automatic deployment. However, adding hexo deploy has issues with access integration errors and potential token private key leakage risks. It is more complicated to handle, so this solution method was not adopted.
(2) When updating the article, add date
in the front-matter
to fix the article creation date.
(3) Cancel Travis CI automatic deployment and use the traditional method of hexo g
and hexo d
for uploading and deployment.
Conclusion#
Although using Travis CI for automatic deployment of Hexo blogs simplifies the steps of uploading and deployment to some extent, it only replaces the traditional upload and deployment commands such as hexo clean, hexo g, hexo d
in the Hexo blog area, with limited effectiveness. It may also be because of insufficient understanding of Travis CI automatic deployment, which makes it slightly challenging to use. Therefore, it is considered to revert to the original traditional upload and deployment method.