asartalo / shfonts

Command line tool to download and use fonts from third-party font hosts

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

shfonts

CI Coverage Status

Command line tool to download fonts from third-party font hosting sites for self-hosting.

Installation

The quickest would be to download the binaries from the latest release from the Release Page. Pick the binary built for your OS.

Installing using Cargo

If you have cargo, installed, you can install shfonts easily with:

cargo install shfonts

Usage

For basic usage, pass in the URL of the CSS font declaration of the hosting site:

shfonts "https://fonts.googleapis.com/css?family=Roboto:300"

Assuming that the URL passed is a CSS file with @font-face declarations, the previous command will download all the font files specified inside it. It will also write a CSS file with contents copied from that CSS file replacing the font URLs declared in @font-face > src url() with the file names of the font files. For example, if the content of the CSS file above is the following:

/* latin */
@font-face {
  font-family: 'Roboto';
  font-style: italic;
  font-weight: 300;
  src: url(https://fonts.gstatic.com/s/roboto/v30/KFOjCnqEu92Fr1Mu51TjASc6CsQ.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

...it will rewrite it to something like the following:

/* latin */
@font-face {
  font-family: 'Roboto';
  font-style: italic;
  font-weight: 300;
  src: url(KFOjCnqEu92Fr1Mu51TjASc6CsQ.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

Setting a Download Directory

If you want to save the font files and the CSS file to a different directory, use --dir or -d option:

shfonts -d "/download/path" "https://fonts.googleapis.com/css?family=Roboto:300"

Customizing the Font URL Path

If you need to customize the font URL inside the url() declaration, use the --font-url-prefix or -p option:

shfonts -p "/assets/fonts/" "https://fonts.googleapis.com/css?family=Roboto:300"

For the previous example CSS file, it will rewrite it like in the following:

/* latin */
@font-face {
  font-family: 'Roboto';
  font-style: italic;
  font-weight: 300;
  src: url(/assets/fonts/KFOjCnqEu92Fr1Mu51TjASc6CsQ.woff2) format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

About

Command line tool to download and use fonts from third-party font hosts

License:BSD 3-Clause "New" or "Revised" License


Languages

Language:Rust 85.1%Language:CSS 14.9%