惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
人人都是产品经理
人人都是产品经理
Cisco Talos Blog
Cisco Talos Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
V
V2EX
博客园 - 三生石上(FineUI控件)
Martin Fowler
Martin Fowler
WordPress大学
WordPress大学
D
Docker
S
SegmentFault 最新的问题
博客园 - 聂微东
美团技术团队
Apple Machine Learning Research
Apple Machine Learning Research
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Last Week in AI
Last Week in AI
M
MIT News - Artificial intelligence
F
Fortinet All Blogs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
The GitHub Blog
The GitHub Blog
GbyAI
GbyAI
L
LangChain Blog
Vercel News
Vercel News
博客园 - 叶小钗
MongoDB | Blog
MongoDB | Blog
Stack Overflow Blog
Stack Overflow Blog
H
Help Net Security
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
The Cloudflare Blog
Engineering at Meta
Engineering at Meta
T
Threat Research - Cisco Blogs
T
Threatpost
Scott Helme
Scott Helme
T
Tailwind CSS Blog
Latest news
Latest news
Stack Overflow Blog
Stack Overflow Blog
Blog — PlanetScale
Blog — PlanetScale
The Register - Security
The Register - Security
罗磊的独立博客
P
Proofpoint News Feed
腾讯CDC
S
Schneier on Security
雷峰网
雷峰网
A
About on SuperTechFans
T
Tenable Blog
F
Full Disclosure
Cyberwarzone
Cyberwarzone
博客园_首页
有赞技术团队
有赞技术团队
K
Kaspersky official blog

文章列表

DNSMgr——聚合管理所有域名DNS解析+自动续签SSL证书并部署 | AirTouchの小站 雨云香港服务器简单测评 | AirTouchの小站 七牛云 AI 狂送 token 实测到底怎么样 | AirTouchの小站 记一次博客被攻击 | AirTouchの小站 给你的 Artalk 评论区配置验证码和垃圾评论检测 | AirTouchの小站 抓紧上车!免费 E3 开发者账号又来了! | AirTouchの小站 Vercel & Cloudflare Worker 项目推荐(2) | AirTouchの小站 用 Zmail 搭建自己的临时邮箱 | AirTouchの小站 IPv6反解域名?手把手带你搞 | AirTouchの小站 用插件实现 Hexo AI 文章摘要 | AirTouchの小站 用 Librechat 部署自己的 AI 网站 | AirTouchの小站 迁移 Umami Cloud 数据到自建的 Umami | AirTouchの小站 raksmart 圣何塞超低价 vps 测评 | AirTouchの小站 Vercel & Github Actions 项目推荐(1) | AirTouchの小站 macOS Tahoe 26中Electron架构卡顿的临时解决方案 | AirTouchの小站 用Obsidian插件增强Stellar写作体验 | AirTouchの小站 复习一下最小生成树 | AirTouchの小站 2025苹果秋季发布会亮点总结 | AirTouchの小站 分享几个artalk邮件通知模板 | AirTouchの小站 博客的图片应该存哪啊? | AirTouchの小站 Pic Smaller——自部署压缩图片的利器 | AirTouchの小站 企业微信的自定义域名邮箱太香了 | AirTouchの小站 所有道听途说,终获眼见为实 | AirTouchの小站 jsDelivr国内公益加速镜像分享 | AirTouchの小站 搭建自己的busuanzi访问量统计服务 用Vercel和Netlify反代你的网站 | AirTouchの小站 用EdgeOne配置反向代理 丢掉丑陋的端口号 拼好鸽香港4区nat机器:月付3.5还要啥自行车! 如何搭建自己的EdgeOne优选域名 | AirTouchの小站 使用 Cloudflare Workers 自动获取必应每日壁纸 | AirTouchの小站 腾讯云EdgeOne免费CDN加速你的网站
修复Vercel部署hexo导致文章的更新时间错误 | AirTouchの小站
AirTouch, me@airtouch.top · 2025-08-25 · via

问题在哪里

当你使用 Vercel 自动化部署 Hexo 博客时会发现,每次 git push 都会导致文章更新时间变为此次提交修改时间,然而实际上文章并没有进行任何修改。

这个问题是由于 git 在推送更新时不会保存文件创建和修改时间等文件元数据。

所以当你每次使用 git clone 上传或下载的项目的文件元数据都是当前系统时间,而不是项目的创建时间。

而在 Hexo 中,文章默认会使用 文件的最后修改时间 作为文章的更新时间,所以CI构建之后进入博客就会看到所有文章修改时间都会变为“刚刚”或者”X分钟以前“这种地狱绘图,因为 git push 上去的文件不会保存元数据。

怎么修复

这里只提供一个很有效但稍有些麻烦的方法(但也没找到更简单的方法),同时也是本站正在使用的方法

由于每次更新推送后 Vercel 都会自动构建部署,我们无法对构建流程进行修改,因此需要关闭 Vercel 的自动构建,转而使用 Github Action来将Hexo 自动化部署到 Vercel

实现原理

在Next主题issue #893@wylu提到了这个问题,@sli1989 提出了以下解决方案

Hi, the updated time with CI deployment can be fixed using this. please check Continuous Integration configurations carefully.

yaml
# Restore last modified time
- "git ls-files -z | while read -d '' path; do touch -d \"$(git log -1 --format=\"@%ct\" \"$path\")\" \"$path\"; done"

该条命令会将文件的最后修改时间修改为 Git 仓库中文件的最后提交时间,即文章的更新时间。

同样使用 find 命令也可以实现这个功能:

bash
find source/_posts -name '*.md' | while read file; do touch -d "$(git log -1 --format="@%ct" "$file")" "$file"; done

准备工作

首先,将 Vercel 项目Github 仓库 的绑定关系解除,因为我们将要在 Github Action 中手动部署 HexoVercel

在 Github Action 中需要使用以下两个环境变量和一个秘钥:

  • VERCEL_ORG_ID
  • VERCEL_PROJECT_ID
  • VERCEL_TOKEN

获取Vercel Access Token

我们需要在 Vercel 中获取一段 Vercel Access Token 用于 Github Action 自动化部署。

点击直达Token创建页面

获取 VERCEL_ORG_ID 和 VERCEL_PROJECT_ID的值

先安装vercel-cli

bash
npm i -g vercel

然后在博客根目录下执行(如果博客目录下有 .vercel 文件夹记得删掉)

bash
vercel link

来创建一个 Vercel 项目,此操作会在博客根目录下生成一个 .vercel 文件夹,在.vercel/project.json 里面包含了 VERCEL_ORG_IDVERCEL_PROJECT_ID

在 Github 仓库中添加 secrets

在你的博客所在的 Github 仓库中,点击 Settings -> Secrets and Variables -> Actions 中添加以下秘钥和环境变量:

  • VERCEL_TOKEN ——前面创建的Vercel Access Token
  • VERCEL_ORG_ID ——.vercel/project.json中的"orgId"字段
  • VERCEL_PROJECT_ID ——.vercel/project.json中的"projectId"字段

填完了之后是这样的

创建 Github Action

在博客创建 .github/workflows/deploy.yml 文件,写入以下内容

yml
name: Deploy Blog to Vercel Production Deployment
env:
  VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
  VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
on:
  push:
    branches:
      - main
jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2
        with:
          persist-credentials: false
          # 0 indicates all history for all branches and tags.
          fetch-depth: 0
      - name: Restore file modification time 🕒
        run: find source/_posts -name '*.md' | while read file; do touch -d "$(git log -1 --format="@%ct" "$file")" "$file"; done
        # run: "git ls-files -z | while read -d '' path; do touch -d \"$(git log -1 --format=\"@%ct\" \"$path\")\" \"$path\"; done"
      - name: Install Vercel-cli🔧
        run: npm install --global vercel@latest
      - name: Pull Vercel Environment Information
        run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }}
      - name: Build Project Artifacts
        run: vercel build --prod --token=${{ secrets.VERCEL_TOKEN }}
      - name: Deploy Project Artifacts to Vercel
        run: vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }}

推送你的博客

现在就大功告成啦~

使用 git push 把本地推送上去,Github Actions 会自动构建并推送到 Vercel

参考文章

blog.oxysc.cc

https://blog.oxysc.cc/GhActionHexo/

www.izeka.eu.org

https://www.izeka.eu.org/2023/08/18/%E4%BF%AE%E5%A4%8DVercel%E9%83%A8%E7%BD%B2hexo%E5%AF%BC%E8%87%B4%E6%96%87%E7%AB%A0%E7%9A%84%E6%9B%B4%E6%96%B0%E6%97%B6%E9%97%B4%E9%94%99%E8%AF%AF/

blog.im0o.top

https://blog.im0o.top/posts/c6d9de72.html