fix: replace colon or other symbol(some systems don't support) in filename

This commit is contained in:
LouisShark 2023-11-20 20:33:09 +08:00
parent b6e7e9e0f9
commit 3b2579197c
3 changed files with 8 additions and 5 deletions

View file

@ -11,11 +11,14 @@ generate_toc() {
echo " $(generate_toc "$file")"
elif [ -f "$file" ] && [[ $file == *.md ]]; then
local title=$(basename "$file" .md)
# Replace Windows incompatible characters with '_'
local safe_title=$(echo "$title" | sed 's/[<>:"\/\\|?*]/_/g')
# shellcheck disable=SC2001
local link=$(echo "$file" | sed "s|^$base_dir/||")
local encoded_link=$(python -c "import urllib.parse; print(urllib.parse.quote('''$link'''))")
echo " - [$title]($encoded_link)"
echo " - [$safe_title]($encoded_link)"
fi
done
}
generate_toc .
generate_toc .