Skip to content

Commit 67df264

Browse files
committed
优化构建脚本:解决不能正确处理 & 字符的问题
1 parent 59112a2 commit 67df264

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

.github/workflows/ci.yml

+4-2
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,10 @@ jobs:
8282
subtitle=$(grep '<h2.*></a>' $file | awk -F'>' '{print $4}' | awk -F'<' '{print $1}')
8383
echo "$file -- $subtitle"
8484
if [ "${subtitle}" != "" ]; then
85-
sed -i "s@ 解题笔记</h1>@: ${subtitle}</h1>@g" $file
86-
sed -i "s@ 解题笔记</title>@: ${subtitle}</title>@g" $file
85+
# 将变量中的 & 替换为 \&
86+
escaped_title=$(sed 's/&/\\&/g' <<< "${subtitle}")
87+
sed -i "s@ 解题笔记</h1>@: ${escaped_title}</h1>@g" $file
88+
sed -i "s@ 解题笔记</title>@: ${escaped_title}</title>@g" $file
8789
fi
8890
fi
8991
done

0 commit comments

Comments
 (0)