Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prepend website url to the font name #22

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,13 @@ the terms.
<dd>Write the generated CSS into <code>OUTPUT</code>. The file will be
overwritten and will be created if it doesn't exist. The default is
<code>font.css</code>.</dd>
<dt><code>-b BASEPATH</code>, <code>--base-path=BASEPATH</code></dt>
<dd>Prepend the base path to the font name. For example,
<code>--base-path="https://example.com/fonts/"</code> will output in
<code>font.css</code>: <code>url('https://example.com/fonts/FONT-NAME.woff2')</code>.</dd>
</dl>


### Positional Arguments
This script accepts an arbitrary number of font specs. A font spec consists
of a font name as accepted by Google's servers, optionally followed by
Expand Down
24 changes: 17 additions & 7 deletions google-font-download
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ lang="latin"
format="all"
url="https://fonts.googleapis.com/css"
urlref=""
basepath=""

# Usage message
usage() {
Expand Down Expand Up @@ -94,6 +95,11 @@ usage() {
overwritten and will be created if it doesn't exist. The
default is \`$css'.

-b BASEPATH, --base-path=BASEPATH
Prepend the base path to the font name. For example,
--base-path="https://example.com/fonts/" will output in
font.css: url('https://example.com/fonts/FONT-NAME.woff2').

POSITIONAL ARGUMENTS
This script accepts an arbitrary number of font specs. A font
spec is any string that Google's servers will accept as
Expand Down Expand Up @@ -146,7 +152,7 @@ fi
# Parse options
if [ $modern_getopt -eq 1 ]; then
ret=0
temp=$(getopt -o u:f:hl:o: --long url:,format:,help,languages:,output: -n "${0:-google-font-download}" -- "$@") || ret=$?
temp=$(getopt -o u:f:hl:o:b: --long url:,format:,help,languages:,output:,base-path: -n "${0:-google-font-download}" -- "$@") || ret=$?
if [ $ret -ne 0 ]; then
echo >&2
usage
Expand All @@ -166,7 +172,7 @@ else

ret=0
# shellcheck disable=SC2048,SC2086
temp=$(getopt u:f:hl:o: $*) || ret=$?
temp=$(getopt u:f:hl:o:b: $*) || ret=$?
if [ $ret -ne 0 ]; then
echo >&2
usage
Expand Down Expand Up @@ -199,6 +205,10 @@ while true; do
css=$2
shift 2
;;
-b|--base-path)
basepath=$2
shift 2
;;
--)
shift
break
Expand Down Expand Up @@ -467,19 +477,19 @@ for family in "${families[@]}"; do
# Generate the CSS statements required to include the downloaded file.
case "$uakey" in
eot)
printf >>"$css" "\\t\\turl('%s?#iefix') format('embedded-opentype')%s\\n" "${fontnameescaped}.$uakey" "${terminator}"
printf >>"$css" "\\t\\turl('%s%s?#iefix') format('embedded-opentype')%s\\n" "$basepath" "${fontnameescaped}.$uakey" "${terminator}"
;;
woff)
printf >>"$css" "\\t\\turl('%s') format('woff')%s\\n" "${fontnameescaped}.$uakey" "${terminator}"
printf >>"$css" "\\t\\turl('%s%s') format('woff')%s\\n" "$basepath" "${fontnameescaped}.$uakey" "${terminator}"
;;
woff2)
printf >>"$css" "\\t\\turl('%s') format('woff2')%s\\n" "${fontnameescaped}.$uakey" "${terminator}"
printf >>"$css" "\\t\\turl('%s%s') format('woff2')%s\\n" "$basepath" "${fontnameescaped}.$uakey" "${terminator}"
;;
ttf)
printf >>"$css" "\\t\\turl('%s') format('truetype')%s\\n" "${fontnameescaped}.$uakey" "${terminator}"
printf >>"$css" "\\t\\turl('%s%s') format('truetype')%s\\n" "$basepath" "${fontnameescaped}.$uakey" "${terminator}"
;;
svg)
printf >>"$css" "\\t\\turl('%s#%s') format('svg')%s\\n" "${fontnameescaped}.${uakey}" "$svgname" "${terminator}"
printf >>"$css" "\\t\\turl('%s%s#%s') format('svg')%s\\n" "$basepath" "${fontnameescaped}.${uakey}" "$svgname" "${terminator}"
;;
esac
done
Expand Down