Last active
March 19, 2019 06:17
-
-
Save yihyang/5678acbe2df02958094d122f037b0959 to your computer and use it in GitHub Desktop.
Bash to generate critical CSS
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
| # check whether critical has been generated | |
| if ! [ -x "$(command -v critical)" ]; then | |
| echo 'Error: critical CSS is not installed.' >&2 | |
| exit 1 | |
| fi | |
| # ask for website | |
| echo "Website URL (without http / https):" | |
| read -r url | |
| # read the page | |
| curl -L $url > temp.html | |
| # screensize | |
| echo Screen size: | |
| read -r screen_size | |
| # echo $url | |
| # extract domain | |
| domain=`expr "$url" : '\([\.a-z0-9\-]*\)'` | |
| # echo $domain | |
| # replace the CSS | |
| perl -pi.bak -e "s/href\=\"\//href\=\"http\:\/\/${domain}\//g" temp.html | |
| # generate critical CSS | |
| critical temp.html > output.css --height $screen_size | |
| pbcopy < output.css | |
| rm temp.html temp.html.bak output.css |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment