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) ### 随机图