Skip to content

Instantly share code, notes, and snippets.

@gja
Created October 24, 2018 19:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gja/bf2d988418b2b3df5659fb05ec2dae1b to your computer and use it in GitHub Desktop.
Save gja/bf2d988418b2b3df5659fb05ec2dae1b to your computer and use it in GitHub Desktop.
Get fonts from Google Font in woff2 and woff
#!/bin/bash -e
function getCSSFile() {
curl -sH "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:27.0) Gecko/20100101 Firefox/27.0" "https://fonts.googleapis.com/css?family=$@"
echo ---------------------
curl -sH "User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.90 Safari/537.36" "https://fonts.googleapis.com/css?family=$@"
}
function mergeCSSfiles() {
gawk -f <(cat << EOF
BEGIN { PRINT_MODE = 0 }
match(\$0, /font-family: (.*);/, a) { FAMILY = a[1]; }
match(\$0, /font-style: (.*);/, a) { STYLE = a[1]; }
match(\$0, /font-weight: (.*);/, a) { WEIGHT = a[1]; }
match(\$0, /src:.*, (url.*)\;/, a) {
if(PRINT_MODE) {
gsub(/;/, ", " PATHS[FAMILY STYLE WEIGHT] ";");
}
else {
PATHS[FAMILY STYLE WEIGHT] = a[1];
}
}
{ if(PRINT_MODE) { print } }
/---------/ { PRINT_MODE = 1 };
EOF
)
}
if [ $# -ne 1 ]; then
echo Usage: $0 \'Lato:400,700\|Lora:400,700\'
exit 1;
fi;
getCSSFile "$@" | mergeCSSfiles
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment