mirror of
https://seed.radicle.dev/rad:z371PVmDHdjJucejRoRYJcDEvD5pp.git
synced 2026-10-18 19:10:34 +08:00
49 lines
1.1 KiB
Bash
Executable File
49 lines
1.1 KiB
Bash
Executable File
#!/bin/sh
|
|
set -e
|
|
|
|
if [ $# -lt 1 ]; then
|
|
echo "usage: $0 <path>..."
|
|
exit 1
|
|
fi
|
|
|
|
if ! command -v tidy 2>&1; then
|
|
echo "error: the 'tidy' executable is required for formatting"
|
|
exit 1
|
|
fi
|
|
|
|
# Function to process a single file
|
|
process() {
|
|
FILE="$1"
|
|
|
|
# Ensure the file exists
|
|
if [ ! -f "$FILE" ]; then
|
|
echo "error: '$FILE' does not exist."
|
|
return
|
|
fi
|
|
|
|
# Format SVG.
|
|
tidy -xml -i -m -q -w 0 "$FILE"
|
|
# Remove `<?xml>` header, if present.
|
|
sed -i '1{/^<?xml/d;}' "$FILE"
|
|
|
|
# Remove all instances of `font-family="..."` and `font-size="..."`
|
|
sed -i -e 's/font-family="[^"]*"//g' -e 's/font-size="16px"//g' "$FILE"
|
|
# Remove comments.
|
|
sed -i -e '/<!--.*-->/d' "$FILE"
|
|
# Replace the contents of <style> tags
|
|
sed -i '/<defs>/,/<\/defs>/c\
|
|
<defs>\
|
|
<style>\
|
|
@import url("/assets/css/fonts.css");\
|
|
svg { font-size: 16px; font-family: "Inter", sans-serif; }\
|
|
</style>\
|
|
</defs>' "$FILE"
|
|
|
|
echo "Processed $FILE"
|
|
}
|
|
|
|
# Iterate over each file provided as an argument
|
|
for file in "$@"; do
|
|
process "$file"
|
|
done
|