README.md 2.58 KB
Newer Older
1 2 3
# Fonts Degooglifier

A script to de-googlify CSS files, downloading relevant fonts in the process. Because privacy matters and self-hosting is a thing.
4 5 6 7

## Usage

```
8
./degooglify.sh [ 'https://fonts.googleapis.com/css?(...)' | file.css ]
9 10
```

11 12 13
**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.

14 15 16 17 18 19
## Operation

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.

20 21 22 23
For relevant `@import` statements it will:
1. download the CSS files, saving them locally
1. replace the URL with the local file name generated based on the URL
1. degooglify the downloaded file
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43

For relevant `src:` statements it:
1. downloads the font files into the `fonts/` subdirectory
1. 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.

## Filenames of downloaded resources

For CSS URLs, the file names of downloaded files are generated by:
1. dropping the `https://fonts.googleapis.com/css?family=` part
1. replacing all occurences of `&` and `&` with `__`
1. replacing all occurences of `|` with `_`
1. replacing all occurences of any of `:+,=` with `-`
1. 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.

44 45 46 47 48 49 50 51 52 53
## Dependencies

An attempt is made to keep dependencies down to as few as possible. Currently these are:
 - Bash 3.x+
 - either `curl` or `wget`
 - GNU `sed` (or any other `sed` flavor that supports: `-i`, `-e`, `-E`)
 - GNU `grep` (or any other `grep` flavor that supports extended regexen)
 - `tr`
 - standard system utilities (`cp`, `mkdir`)

54 55 56 57 58 59 60
## Bugs and feature requests

Please send bug requests and feature reports to `tech(at)occrp.org`.

## License

GNU Affero General Public License, version 3.