we can now handle direct downloads from fonts.googleapis.com/css (fixing #3)

parent e93713b4
......@@ -3,21 +3,19 @@
#
# Font DeGooglifier
#
#
# $1, ... - CSS files to de-googlify
# $1, ... - CSS files or URLs to de-googlify
#
#
# the actual workhorse
#
# $1 -- the CSS file to degooglify
# $2 -- font directory to dump the fonts to
# $1 -- font directory to dump the fonts to
# $2 -- the CSS file to degooglify
function degooglify_css() {
# source CSS file
CSS_SRC="$1"
CSS_SRC="$2"
# destination CSS file
CSS_DEST="${CSS_SRC/.css/.degooglified.css}"
......@@ -27,7 +25,7 @@ function degooglify_css() {
# destination directory
# assuming it exists and is writeable
FONT_DIR="$2"
FONT_DIR="$1"
# inform
echo "+-- de-googlifying: $CSS_SRC"
......@@ -74,6 +72,44 @@ function degooglify_css() {
IFS="$OLDIFS"
}
#
# handle a CSS file available from fonts.googleapis.com
#
# $1 -- font directory to dump the fonts to
# $2 -- URL
function degooglify_remote() {
# destination directory
# assuming it exists and is writeable
FONT_DIR="$1"
# remote CSS file
CSS_REMOTE="$2"
# reality check -- is this a fonts.googleapis.com/css link?
if [[ $CSS_REMOTE != "https://fonts.googleapis.com/css"* ]]; then
echo "ERROR: supplied URL is not a link to fonts.googleapis.com: '$CSS_REMOTE'"
fi
# we're good, I guess
# get the filename from the URL
CSS_LOCAL="$( echo "$CSS_REMOTE" | sed -r -e 's%https://fonts.googleapis.com/css\?family=%%' -e 's/&/__/' | tr '|:+,=' '_-' ).css"
# inform
echo "+-- downloading remote CSS:"
echo " +-- source URL : $CSS_REMOTE"
echo " +-- destination file : $CSS_LOCAL"
# download
wget -nc --progress=dot -O "$CSS_LOCAL" "$CSS_REMOTE"
# handle the downlaoded file
degooglify_css "$FONT_DIR" "$CSS_LOCAL"
}
# target directory
# TODO: make that configurable on the command line
TARGET_FONT_DIR="fonts/"
......@@ -87,6 +123,14 @@ TARGET_FONT_DIR=${TARGET_FONT_DIR%/}
[ -w "$TARGET_FONT_DIR" ] || ( echo "ERROR: destination font directory not writeable: '$TARGET_FONT_DIR'" && exit 1 )
# do the magic
for CSS_FILE in "$@"; do
degooglify_css "$CSS_FILE" "$TARGET_FONT_DIR"
for SOURCE_OF_CSS in "$@"; do
# are we dealing with a remote resource?
if [[ ${SOURCE_OF_CSS,,} == "https://"* ]]; then
# yes we are! deal with it, then
degooglify_remote "$TARGET_FONT_DIR" "$SOURCE_OF_CSS"
else
# nope, all local
degooglify_css "$TARGET_FONT_DIR" "$SOURCE_OF_CSS"
fi
done
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment