From 0e6a2ff6a36d7f304c9e468f6e5ac23db518ae30 Mon Sep 17 00:00:00 2001 From: Regis Philibert Date: Thu, 1 Dec 2022 14:42:08 -0500 Subject: [PATCH] Fix mimetype issues when maintype/subtype is empty --- core/fonts/private/GetMediaType.html | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/core/fonts/private/GetMediaType.html b/core/fonts/private/GetMediaType.html index d603bf4..dccf608 100644 --- a/core/fonts/private/GetMediaType.html +++ b/core/fonts/private/GetMediaType.html @@ -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 ` 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 }} \ No newline at end of file