fix: 还原机房 PATH 兼容性问题 + 链接检查器国内网络适配#21
Conversation
There was a problem hiding this comment.
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.
| req.on('timeout', () => { | ||
| req.destroy(); | ||
| resolve({ status: 'timeout', error: '请求超时' }); | ||
| if (attempt < retries) { | ||
| setTimeout(() => makeRequest(method, attempt + 1), 500); | ||
| } else { |
| const srcFallback = path.resolve(rootDir, 'src', assetsMatch[0].replace(/^(\.\.\/)+/, '')); | ||
| if (fs.existsSync(srcFallback)) { | ||
| return srcFallback; | ||
| } |
| Add-ToPath -Dir $nodeDir | ||
| Write-Ok "已确保 Node.js 目录在当前会话 PATH 中" |
There was a problem hiding this comment.
💡 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".
| 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'))) { |
There was a problem hiding this comment.
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 👍 / 👎.
| 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(/^(\.\.\/)+/, '')); |
There was a problem hiding this comment.
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 👍 / 👎.
修复还原机房兼容性问题及链接检查器改进
变更摘要
本次 PR 包含 4 个文件的修改,分为两类:
1. fix(scripts/check-links): 修复 Windows 兼容性并增强国内网络适配
文件:
scripts/check-links.js问题
about.md引用../../assets/images/avatar.jpg,检查器报错断链,因为src/assets在构建时才复制到dist/assetslearn.microsoft.com、github.com在国内网络下频繁ECONNRESET或超时,导致npm run check:all失败修复
/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而失败:修复
在 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,无预装环境)下完整运行验证:
npm testnpm run buildnpm run check:allnpm run lint变更文件