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

推荐订阅源

Google DeepMind News
Google DeepMind News
博客园_首页
H
Help Net Security
T
Tailwind CSS Blog
S
SegmentFault 最新的问题
GbyAI
GbyAI
Scott Helme
Scott Helme
D
Docker
Hacker News: Ask HN
Hacker News: Ask HN
P
Privacy & Cybersecurity Law Blog
Jina AI
Jina AI
雷峰网
雷峰网
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Spread Privacy
Spread Privacy
G
GRAHAM CLULEY
C
Cisco Blogs
The Hacker News
The Hacker News
F
Full Disclosure
Y
Y Combinator Blog
Blog — PlanetScale
Blog — PlanetScale
Recent Announcements
Recent Announcements
G
Google Developers Blog
量子位
K
Kaspersky official blog
Cisco Talos Blog
Cisco Talos Blog
The Cloudflare Blog
A
About on SuperTechFans
C
Cybersecurity and Infrastructure Security Agency CISA
Last Week in AI
Last Week in AI
博客园 - 三生石上(FineUI控件)
Microsoft Security Blog
Microsoft Security Blog
Martin Fowler
Martin Fowler
T
Tenable Blog
P
Palo Alto Networks Blog
H
Heimdal Security Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
W
WeLiveSecurity
Schneier on Security
Schneier on Security
The Register - Security
The Register - Security
F
Fortinet All Blogs
Stack Overflow Blog
Stack Overflow Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
The Blog of Author Tim Ferriss
N
News and Events Feed by Topic
Hugging Face - Blog
Hugging Face - Blog
小众软件
小众软件
V
V2EX
爱范儿
爱范儿

AirTouchの小站

DNSMgr——聚合管理所有域名DNS解析+自动续签SSL证书并部署 | AirTouchの小站 雨云香港服务器简单测评 | AirTouchの小站 七牛云 AI 狂送 token 实测到底怎么样 | AirTouchの小站 记一次博客被攻击 | AirTouchの小站 给你的 Artalk 评论区配置验证码和垃圾评论检测 | AirTouchの小站 抓紧上车!免费 E3 开发者账号又来了! | AirTouchの小站 Vercel & Cloudflare Worker 项目推荐(2) | AirTouchの小站 用 Zmail 搭建自己的临时邮箱 | AirTouchの小站 IPv6反解域名?手把手带你搞 | AirTouchの小站 AirTouchの小站 AirTouchの小站 AirTouchの小站 AirTouchの小站 AirTouchの小站 macOS Tahoe 26中Electron架构卡顿的临时解决方案 | AirTouchの小站 用Obsidian插件增强Stellar写作体验 | AirTouchの小站 复习一下最小生成树 | AirTouchの小站 2025苹果秋季发布会亮点总结 | AirTouchの小站 分享几个artalk邮件通知模板 | AirTouchの小站 博客的图片应该存哪啊? | AirTouchの小站 Pic Smaller——自部署压缩图片的利器 | AirTouchの小站 企业微信的自定义域名邮箱太香了 | AirTouchの小站 所有道听途说,终获眼见为实 | AirTouchの小站 jsDelivr国内公益加速镜像分享 | AirTouchの小站 搭建自己的busuanzi访问量统计服务 | AirTouchの小站 用Vercel和Netlify反代你的网站 | AirTouchの小站 用EdgeOne配置反向代理 丢掉丑陋的端口号 | AirTouchの小站 拼好鸽香港4区nat机器:月付3.5还要啥自行车! | AirTouchの小站 博客的新域名——xsl.im | AirTouchの小站 如何搭建自己的EdgeOne优选域名 | AirTouchの小站 用EdgeOne加速CloudflareR2存储桶 | AirTouchの小站 EdgeOne自动化上传证书并部署 | AirTouchの小站 你需要把PicGo换成PicList了! | AirTouchの小站 Cursor屏蔽中国大陆?给你解决方案! | AirTouchの小站 使用 Cloudflare Workers 自动获取必应每日壁纸 | AirTouchの小站 题解:P9509『STA - R3』Aulvwc | AirTouchの小站 题解:P11140 [APC001] E - Linear Map | AirTouchの小站 Phira多人联机服务器搭建&使用教程 | AirTouchの小站 腾讯云EdgeOne免费CDN加速你的网站 | AirTouchの小站 Hexo 博客收录指南 | AirTouchの小站 题解:P12646 [KOI 2024 Round 1] 升序 | AirTouchの小站 Cloudflare CDN优选IP加速你的网站 | AirTouchの小站 Giffgaff在线生成esim二维码 | Giffgaff sim转eSIM指南 | AirTouchの小站 AirTouchの小站 AirTouchの小站 Hexo Stellar 主题装修笔记 | AirTouchの小站 AirTouchの小站 AirTouchの小站 AirTouchの小站
修复Vercel部署hexo导致文章的更新时间错误 | AirTouchの小站
AirTouch, me@airtouch.top · 2025-08-25 · via AirTouchの小站

问题在哪里

当你使用 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