Created
October 24, 2018 19:23
-
-
Save gja/bf2d988418b2b3df5659fb05ec2dae1b to your computer and use it in GitHub Desktop.
Get fonts from Google Font in woff2 and woff
This file contains hidden or 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
#!/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