Skip to content

Commit

Permalink
Fix mimetype issues when maintype/subtype is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
regisphilibert committed Dec 1, 2022
1 parent 01e9c0b commit 0e6a2ff
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions core/fonts/private/GetMediaType.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,30 @@
@returns String

*/}}
{{ $MainType := "font" }}
{{ $SubType := "woff2" }}
{{/* It appears CloudFlare produces an empty string when calling .MediaType.SubType on a 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 }}
{{ $MainType := .MediaType.MainType }}
{{ with .MediaType.MainType }}
{{ $MainType = . }}
{{ end }}

{{ $MediaType := "%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 printf "%s/%s" $MainType $SubType }}

0 comments on commit 0e6a2ff

Please sign in to comment.