Skip to content

fix: 还原机房 PATH 兼容性问题 + 链接检查器国内网络适配#21

Merged
yang12535 merged 2 commits into
mainfrom
fix/restore-workflow-and-link-checker-v2
Jun 3, 2026
Merged

fix: 还原机房 PATH 兼容性问题 + 链接检查器国内网络适配#21
yang12535 merged 2 commits into
mainfrom
fix/restore-workflow-and-link-checker-v2

Conversation

@yang12535

Copy link
Copy Markdown
Owner

修复还原机房兼容性问题及链接检查器改进

变更摘要

本次 PR 包含 4 个文件的修改,分为两类:

  1. 博客项目代码修复(链接检查器兼容性)
  2. 文章内容修复(还原机房装机脚本 PATH 问题 + 占位符链接)

1. fix(scripts/check-links): 修复 Windows 兼容性并增强国内网络适配

文件: scripts/check-links.js

问题

  • 构建资源断链误报about.md 引用 ../../assets/images/avatar.jpg,检查器报错断链,因为 src/assets 在构建时才复制到 dist/assets
  • 国内网络外部链接检查失败learn.microsoft.comgithub.com 在国内网络下频繁 ECONNRESET 或超时,导致 npm run check:all 失败
  • 缺乏重试机制:单次请求失败即判定为断链

修复

  • 构建资源 fallback:对以 /assets/ 开头的绝对路径和包含 assets/ 的相对路径,在根目录不存在时自动尝试 src/ 目录
  • 重试机制checkSingleUrl 增加 retries = 2 参数,超时/网络错误时自动重试(间隔 500ms)
  • --warn-external 选项:新增命令行选项,将 ECONNRESET/ETIMEDOUT/ENOTFOUND/超时等网络层错误降级为警告,不阻塞 CI;HTTP 错误码(404/500 等)仍视为错误

2. chore(package): check:links 默认启用 --warn-external

文件: package.json

适配国内网络环境,让 npm run check:all 在机房/国内网络下不会因为偶发的连接重置而失败。


3. fix(content): 修复还原机房装机脚本的 PATH 兼容性问题

文件: content/posts/win-restore-workflow.md

问题(实测发现)

Node.js MSI 安装程序将 C:\Program Files\nodejs 写入注册表 PATH,但当前 PowerShell 会话不刷新。脚本原设计是所有组件安装完毕后(第 7 步)统一添加 PATH,但第 5 步安装 Bun 时,install.js 内部调用 node 命令,因找不到 node 而失败:

npm error 'node' is not recognized as an internal or external command
npm 安装 bun 失败

修复

在 Node.js 安装/跳过后立即调用 Add-ToPath -Dir $nodeDir,确保后续步骤在当前会话中能找到 node


4. fix(content): 修复占位符链接

文件: content/posts/kimi-cli-install-win.md

https://github.com/your-repo 替换为真实的 https://github.com/yang12535/blog


测试验证

在还原机房环境(Windows PowerShell 5.1,无预装环境)下完整运行验证:

验证项 结果
装机脚本完整运行(PS7 + Git + Node.js + npm + Bun + Kimi Code) ✅ 通过
npm test ✅ 113/113 通过
npm run build ✅ 成功
npm run check:all ✅ 全部通过
npm run lint ✅ 通过

变更文件

scripts/check-links.js                  | +72 lines  (fallback + retries + warn-external)
package.json                            | +1 line    (--warn-external)
content/posts/win-restore-workflow.md   | +5 lines   (PATH 立即生效)
content/posts/kimi-cli-install-win.md   | +1 line    (修复占位符链接)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

该 PR 主要解决两类问题:一是改进链接检查脚本在国内网络/不稳定网络环境下的可用性(并减少构建产物资源的误报断链);二是修复 Windows 还原机房装机流程文档中的 PATH 兼容性与占位符链接问题。

Changes:

  • scripts/check-links.js:增加构建资源的 src/ fallback、外链检查重试、以及 --warn-external 将网络层错误降级为告警的能力。
  • package.json:默认在 check:links 启用 --warn-external,降低国内网络波动导致的 CI 失败概率。
  • 文档内容修复:装机脚本确保 Node 目录在当前会话 PATH 生效;替换占位符仓库链接为真实地址。

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
scripts/check-links.js 链接检查器增强:资源 fallback、重试、外链网络错误降级为 warning
package.json check:links 默认启用 --warn-external
content/posts/win-restore-workflow.md 装机流程文档:Node 安装后立即补齐当前会话 PATH
content/posts/kimi-cli-install-win.md 将占位符 GitHub 链接替换为真实仓库地址

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread scripts/check-links.js
Comment on lines 96 to +100
req.on('timeout', () => {
req.destroy();
resolve({ status: 'timeout', error: '请求超时' });
if (attempt < retries) {
setTimeout(() => makeRequest(method, attempt + 1), 500);
} else {
Comment thread scripts/check-links.js
Comment on lines +169 to +172
const srcFallback = path.resolve(rootDir, 'src', assetsMatch[0].replace(/^(\.\.\/)+/, ''));
if (fs.existsSync(srcFallback)) {
return srcFallback;
}
Comment thread content/posts/win-restore-workflow.md Outdated
Comment on lines +212 to +213
Add-ToPath -Dir $nodeDir
Write-Ok "已确保 Node.js 目录在当前会话 PATH 中"
@yang12535 yang12535 merged commit 44691f8 into main Jun 3, 2026
3 checks passed
@yang12535 yang12535 deleted the fix/restore-workflow-and-link-checker-v2 branch June 3, 2026 12:41

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a1e6ae4430

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread scripts/check-links.js
okExternal.push(r);
} else if (r.status === 'redirect') {
okExternal.push(r); // 重定向视为可用
} else if (warnExternal && (r.error === '请求超时' || r.error?.includes('ECONNRESET') || r.error?.includes('ETIMEDOUT') || r.error?.includes('ENOTFOUND'))) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Do not downgrade DNS failures by default

When npm run check:links now runs with --warn-external, this branch treats any ENOTFOUND as a warning and exits 0. That hides genuinely broken links whose host no longer exists or is misspelled, because Node reports those permanent DNS failures with the same code; HTTP 404s still fail, but a dead domain can now be published without failing check:all. Consider limiting the warning mode to transient errors or keeping DNS failures fatal unless this is an explicitly local-only invocation.

Useful? React with 👍 / 👎.

Comment thread scripts/check-links.js
Comment on lines +173 to +177
if (!fs.existsSync(resolved) && clean.includes('assets/')) {
// 更通用的方式:把相对路径中指向 assets 的部分映射到 src/assets
const assetsMatch = clean.match(/(?:\.\.\/)*assets\/.*$/);
if (assetsMatch) {
const srcFallback = path.resolve(rootDir, 'src', assetsMatch[0].replace(/^(\.\.\/)+/, ''));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject asset relatives that won't resolve from post pages

This fallback maps any relative path containing assets/ to src/assets, so a post link such as ../assets/images/foo.png or ./assets/images/foo.png passes as soon as that file exists under src/assets. The generated post pages are written under dist/posts/<slug>/index.html while assets are copied to dist/assets, so only ../../assets/... (or /assets/...) resolves there in the browser; the shorter relative forms would publish as /posts/assets/... or /posts/<slug>/assets/... and 404 while the checker exits successfully.

Useful? React with 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants