A script to de-googlify CSS files, downloading relevant fonts in the process. Because privacy matters and self-hosting is a thing.
./degooglify.sh [ 'https://fonts.googleapis.com/css?(...)' | file.css ]
Please note: remember to put the URL in quotes, or otherwise escape any special characters.
Google Fonts CSS URLs contain the pipe character (|
) which will be interpreted by your shell and cause the URL passed to degooglify.sh
to be incomplete.
The degooglify.sh
script takes as arguments local files and URLs (leading to fonts.googleapis.com
). It handles multiple arguments, including mixing of URLs and files.
It then downloads the CSS files from URLs provided, and in all local and downloaded files looks for @import
(with URL pointing to fonts.googleapis.com
) and src:
(with URL pointing to fonts.gstatic.com
) statements.
For relevant @import
statements it will:
- download the CSS files, saving them locally
- replace the URL with the local file name generated based on the URL
- degooglify the downloaded file
For relevant src:
statements it:
- downloads the font files into the
fonts/
subdirectory - replaces the URLs with downloaded font files' locations
Original files are never modified. Instead, copies are created with .degooglified
added to the name right before the .css
extension.
For CSS URLs, the file names of downloaded files are generated by:
- dropping the
https://fonts.googleapis.com/css?family=
part - replacing all occurences of
&
and&
with__
- replacing all occurences of
|
with_
- replacing all occurences of any of
:+,=
with-
- adding
.degooglified
before the final.css
This is designed to give an informative file name, containing font families, styles, and information on scripts included, based on the information available in the original CSS URL.
For font URLs, the file names of downloaded files are generated by taking the font name from local()
stanza in the src:
statement, and adding the extension taken from the URL.
An attempt is made to keep dependencies down to as few as possible. Currently these are:
- Bash 3.x+
- either
curl
orwget
- GNU
sed
(or any othersed
flavor that supports:-i
,-e
,-E
) - GNU
grep
(or any othergrep
flavor that supports extended regexen) tr
- standard system utilities (
cp
,mkdir
)
Please send bug requests and feature reports to tech(at)occrp.org
.
GNU Affero General Public License, version 3.