-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Partially refactors HUGE/Fonts (#81)
* Partially refactors HUGE/Fonts Add `base`setting, improve `preload` logic and UX Fixes #80 * Fix mimetype issues when maintype/subtype is empty * Fix pesky formatting * Ensure not font-face at rule is printed if no files are found * Rename `base` setting to `cascade` Move `preload` setting to font (use cascade for global) * Add "tech" font setting (variable fonts)
- Loading branch information
1 parent
33b64c8
commit e3ed7df
Showing
7 changed files
with
177 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
{{/* | ||
GetFormat | ||
Retrieves the font format of a given resource | ||
|
||
@author @regisphilibert | ||
|
||
@context Resource (.) | ||
|
||
@access private | ||
|
||
@returns String | ||
|
||
*/}} | ||
{{ $MainType := "font" }} | ||
{{ $SubType := "woff2" }} | ||
{{/* It appears CloudFlare produces an empty string when calling .MediaType.MainType or .MediaType.SubType on a woff2... | ||
As this is by far the best font format these days in terms of support and optimization, | ||
making it default to ensure it is not botched by cloudflare is "ok". | ||
*/}} | ||
{{ with .MediaType.SubType }} | ||
{{ $SubType = . }} | ||
{{ end }} | ||
{{ with .MediaType.MainType }} | ||
{{ $MainType = . }} | ||
{{ end }} | ||
|
||
{{ $format := printf "%s/%s" $MainType $SubType }} | ||
|
||
{{/* Another weirdness for some files depending on hosting plaftorm. | ||
Some woff file would return application/font-woff | ||
But Chrome will print a `<link rel=preload> has an unsupported `type` value` warning on non-font "types". | ||
*/}} | ||
{{ $irregular := dict | ||
"application/font-woff" "font/woff" | ||
}} | ||
{{ with index $irregular $format }} | ||
{{ $format = . }} | ||
{{ end }} | ||
|
||
{{ return $format }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{{/* | ||
SanitizeProperties | ||
Eliminate any property which is not a font property to be used in @font-face declaration. | ||
Also clean the key (font-display > display) | ||
|
||
@author @regisphilibert | ||
|
||
@context Map (.) | ||
|
||
@access private | ||
|
||
@returns Map | ||
|
||
*/}} | ||
{{ $s := newScratch }} | ||
{{ $s.Set "data" dict }} | ||
|
||
{{ $property_keys := slice | ||
"family" | ||
"weight" | ||
"style" | ||
"display" | ||
"variant" | ||
"feature-settings" | ||
"variation-settings" | ||
"stretch" | ||
}} | ||
{{ range $key := $property_keys }} | ||
{{ with index $ $key }} | ||
{{ $s.SetInMap "data" $key . }} | ||
{{ else }} | ||
{{ with index $ (printf "font-" $key) }} | ||
{{ $s.SetInMap "data" $key . }} | ||
{{ end }} | ||
{{ end }} | ||
{{ end }} | ||
|
||
{{ return $s.Get "data" }} |