From 3d63d3e5924a2e83b44977e45e72ce364a8a7ea3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E5=8F=89=E6=A0=91=E6=A0=91?= Date: Mon, 12 Jan 2026 23:31:53 +0800 Subject: [PATCH] =?UTF-8?q?fix(scripts):=20=E4=BF=AE=E5=A4=8D=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E8=B7=AF=E5=BE=84=E5=A4=84=E7=90=86=E4=B8=AD=E7=9A=84?= =?UTF-8?q?=E6=8B=AC=E5=8F=B7=E5=92=8C=E7=A9=BA=E6=A0=BC=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改正则表达式以支持URL中包含括号的情况 - 改进图片重命名逻辑,处理多种路径格式 - 移除路径中的%20空格编码 --- scripts/del-space.js | 20 ++++++++++++++---- ...tps___blogacoforkcom__多地区多线路HTTP测速(1).png} | Bin src/content/posts/fenliu.md | 2 +- 3 files changed, 17 insertions(+), 5 deletions(-) rename src/content/assets/images/{https___blog.acofork.com__多地区多线路HTTP测速 (1).png => https___blogacoforkcom__多地区多线路HTTP测速(1).png} (100%) diff --git a/scripts/del-space.js b/scripts/del-space.js index fb09c7195..cd20db674 100644 --- a/scripts/del-space.js +++ b/scripts/del-space.js @@ -63,7 +63,8 @@ async function processMarkdownFile(filePath) { } // 2. 处理 Markdown 图片语法 ![alt](url) - const markdownImageRegex = /!\[.*?\]\((.*?)\)/g; + // 修复:支持 URL 中包含一层括号,例如 image(1).png + const markdownImageRegex = /!\[.*?\]\(((?:[^()]+|\([^()]*\))+)\)/g; while ((match = markdownImageRegex.exec(content)) !== null) { const fullUrl = match[1]; // 去除可能的 title 部分 @@ -169,7 +170,18 @@ async function handleImageRename(markdownPath, imagePath) { return null; } else { // 相对路径 - absolutePath = path.resolve(markdownDir, decodedPath); + const candidates = [decodedPath]; + if (decodedPath !== imagePath) { + candidates.push(imagePath); + } + + for (const candidate of candidates) { + const candidateAbs = path.resolve(markdownDir, candidate); + if (fs.existsSync(candidateAbs)) { + absolutePath = candidateAbs; + break; + } + } } if (!fs.existsSync(absolutePath)) { @@ -248,8 +260,8 @@ async function handleImageRename(markdownPath, imagePath) { } else { newReferencePath = imagePath.substring(0, lastSeparatorIndex + 1) + newFilename; } - - return newReferencePath; + + return newReferencePath.replace(/%20/g, ""); } /** diff --git a/src/content/assets/images/https___blog.acofork.com__多地区多线路HTTP测速 (1).png b/src/content/assets/images/https___blogacoforkcom__多地区多线路HTTP测速(1).png similarity index 100% rename from src/content/assets/images/https___blog.acofork.com__多地区多线路HTTP测速 (1).png rename to src/content/assets/images/https___blogacoforkcom__多地区多线路HTTP测速(1).png diff --git a/src/content/posts/fenliu.md b/src/content/posts/fenliu.md index 8e88fe837..354a5e827 100644 --- a/src/content/posts/fenliu.md +++ b/src/content/posts/fenliu.md @@ -68,7 +68,7 @@ Umami,用于在网站插入一个JS来进行访客统计以及展示访客信 ### 博客本体 -![](../assets/images/https___blog.acofork.com__多地区多线路HTTP测速%20(1).png) +![](../assets/images/https___blogacoforkcom__多地区多线路HTTP测速(1).png) ### Umami ![](../assets/images/https___umamiacoforkcom__多地区多线路HTTP测速.png) ### 随机图