-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: try to rename and escape : characters in filenames
- Loading branch information
Showing
2 changed files
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/bin/bash | ||
|
||
# Set locale to UTF-8 to avoid illegal byte sequence errors | ||
export LC_CTYPE=C | ||
export LANG=C | ||
|
||
STATIC_FILES_FOLDER_PATH="./docs-website" | ||
|
||
# Find all files with colons in their names, rename them, and update references | ||
find $STATIC_FILES_FOLDER_PATH -depth -name '*:*' \ | ||
| while IFS= read -r file; do | ||
# Generate the new name by replacing colons with underscores | ||
new_name="$(dirname "$file")/$(basename "$file" | tr ':' '_')" | ||
|
||
# Rename the file | ||
mv "$file" "$new_name" | ||
|
||
# Escape slashes and special characters for sed | ||
escaped_file=$(printf '%s\n' "$(basename "$file")" | sed 's/[][\\/.^$*]/\\&/g') | ||
escaped_new_name=$(printf '%s\n' "$(basename "$new_name")" | sed 's/[][\\/.^$*]/\\&/g') | ||
|
||
# Update only the specific references to the renamed file within the documentation | ||
grep -rl "$escaped_file" $STATIC_FILES_FOLDER_PATH \ | ||
| xargs sed -i '' "s/$escaped_file/$escaped_new_name/g" | ||
done |