mirror of
https://github.com/afoim/fuwari.git
synced 2026-01-31 09:03:18 +08:00
fix(scripts): 修复图片路径处理中的括号和空格问题
- 修改正则表达式以支持URL中包含括号的情况 - 改进图片重命名逻辑,处理多种路径格式 - 移除路径中的%20空格编码
This commit is contained in:
@@ -63,7 +63,8 @@ async function processMarkdownFile(filePath) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 2. 处理 Markdown 图片语法 
|
// 2. 处理 Markdown 图片语法 
|
||||||
const markdownImageRegex = /!\[.*?\]\((.*?)\)/g;
|
// 修复:支持 URL 中包含一层括号,例如 image(1).png
|
||||||
|
const markdownImageRegex = /!\[.*?\]\(((?:[^()]+|\([^()]*\))+)\)/g;
|
||||||
while ((match = markdownImageRegex.exec(content)) !== null) {
|
while ((match = markdownImageRegex.exec(content)) !== null) {
|
||||||
const fullUrl = match[1];
|
const fullUrl = match[1];
|
||||||
// 去除可能的 title 部分
|
// 去除可能的 title 部分
|
||||||
@@ -169,7 +170,18 @@ async function handleImageRename(markdownPath, imagePath) {
|
|||||||
return null;
|
return null;
|
||||||
} else {
|
} 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)) {
|
if (!fs.existsSync(absolutePath)) {
|
||||||
@@ -249,7 +261,7 @@ async function handleImageRename(markdownPath, imagePath) {
|
|||||||
newReferencePath = imagePath.substring(0, lastSeparatorIndex + 1) + newFilename;
|
newReferencePath = imagePath.substring(0, lastSeparatorIndex + 1) + newFilename;
|
||||||
}
|
}
|
||||||
|
|
||||||
return newReferencePath;
|
return newReferencePath.replace(/%20/g, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 1.5 MiB After Width: | Height: | Size: 1.5 MiB |
@@ -68,7 +68,7 @@ Umami,用于在网站插入一个JS来进行访客统计以及展示访客信
|
|||||||
|
|
||||||
### 博客本体
|
### 博客本体
|
||||||
|
|
||||||
.png)
|
.png)
|
||||||
### Umami
|
### Umami
|
||||||

|

|
||||||
### 随机图
|
### 随机图
|
||||||
|
|||||||
Reference in New Issue
Block a user