diff --git a/run.sh b/run.sh index 83532a7..076964f 100644 --- a/run.sh +++ b/run.sh @@ -22,8 +22,65 @@ sed -i "s|{{CheckTime}}|$DATE|g" tmp/chrome.xml ./util/generator.sh stable-x86 stable-x64 beta-x86 beta-x64 dev-x86 dev-x64 canary-x86 canary-x64 -xmllint --format tmp/chrome.xml > tmp/api/chrome.xml -xmllint --noblanks tmp/chrome.xml > tmp/api/chrome.min.xml +# Function to format XML +format_xml() { + local input=$1 + local output=$2 + + # Read input file and process it + sed ' + # Add newline after elements that end with > + s/>/>\n/g + # Remove empty lines + /^[[:space:]]*$/d + ' "$input" | awk ' + # Initialize indent level + BEGIN { indent = 0 } + + # Processing each line + { + # Remove leading/trailing whitespace + gsub(/^[ \t]+|[ \t]+$/, "") + + # Decrease indent for closing tags + if (match($0, "^$")) { + indent += 2 + } + } + ' > "$output" +} + +# Function to minify XML +minify_xml() { + local input=$1 + local output=$2 + + # Remove newlines, leading/trailing whitespace, and consolidate spaces + tr -d '\n' < "$input" | \ + sed -E ' + # Remove spaces between tags + s/>[[:space:]]+ "$output" +} + +# Format XML +format_xml "tmp/chrome.xml" "tmp/api/chrome.xml" + +# Minify XML +minify_xml "tmp/chrome.xml" "tmp/api/chrome.min.xml" cp -rf tmp/index.html public/index.html cp -rf tmp/api/chrome.xml public/api/chrome.xml