mirror of
https://github.com/afoim/fuwari.git
synced 2026-01-31 00:53:19 +08:00
fix(scripts): 修复图片路径处理中的括号和空格问题
- 修改正则表达式以支持URL中包含括号的情况 - 改进图片重命名逻辑,处理多种路径格式 - 移除路径中的%20空格编码
This commit is contained in:
@@ -63,7 +63,8 @@ async function processMarkdownFile(filePath) {
|
||||
}
|
||||
|
||||
// 2. 处理 Markdown 图片语法 
|
||||
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, "");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user