media: support application/manifest+json
authorRohan Kumar <seirdy@seirdy.one>
Wed, 9 Jun 2021 23:13:46 +0000 (16:13 -0700)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 18 Jun 2021 11:11:44 +0000 (13:11 +0200)
The standard file extension for Web App Manifest files is
".webmanifest". This commit allows Hugo to recognize .webmanifest files
as "application/manifest+json" files and to minify them using its
JSON minifier.

The .webmanifest file extension is recommended in the w3c spec to
simplify media type registration:
https://www.w3.org/TR/appmanifest/#media-type-registration

Webhint docs are also relevant:
https://webhint.io/docs/user-guide/hints/hint-manifest-file-extension/

Closes #8624

media/mediaType.go
minifiers/minifiers.go
output/outputFormat.go

index 817ea1ba81d14d2f518f36e5112b65a8dbb27c1e..d3f212ad32316dad6a31a3d67ff46dfe9b20196a 100644 (file)
@@ -166,13 +166,14 @@ var (
        TSXType        = newMediaType("text", "tsx", []string{"tsx"})
        JSXType        = newMediaType("text", "jsx", []string{"jsx"})
 
-       JSONType = newMediaType("application", "json", []string{"json"})
-       RSSType  = newMediaTypeWithMimeSuffix("application", "rss", "xml", []string{"xml"})
-       XMLType  = newMediaType("application", "xml", []string{"xml"})
-       SVGType  = newMediaTypeWithMimeSuffix("image", "svg", "xml", []string{"svg"})
-       TextType = newMediaType("text", "plain", []string{"txt"})
-       TOMLType = newMediaType("application", "toml", []string{"toml"})
-       YAMLType = newMediaType("application", "yaml", []string{"yaml", "yml"})
+       JSONType           = newMediaType("application", "json", []string{"json"})
+       WebAppManifestType = newMediaTypeWithMimeSuffix("application", "manifest", "json", []string{"webmanifest"})
+       RSSType            = newMediaTypeWithMimeSuffix("application", "rss", "xml", []string{"xml"})
+       XMLType            = newMediaType("application", "xml", []string{"xml"})
+       SVGType            = newMediaTypeWithMimeSuffix("image", "svg", "xml", []string{"svg"})
+       TextType           = newMediaType("text", "plain", []string{"txt"})
+       TOMLType           = newMediaType("application", "toml", []string{"toml"})
+       YAMLType           = newMediaType("application", "yaml", []string{"yaml", "yml"})
 
        // Common image types
        PNGType  = newMediaType("image", "png", []string{"png"})
@@ -206,6 +207,7 @@ var DefaultTypes = Types{
        TSXType,
        JSXType,
        JSONType,
+       WebAppManifestType,
        RSSType,
        XMLType,
        SVGType,
index e76e56afd57f18237868f5cb8ea312842bf637a8..3ac285ecbf8f6281dc310a8c9b5d436f1bd88e4b 100644 (file)
@@ -78,7 +78,7 @@ func New(mediaTypes media.Types, outputFormats output.Formats, cfg config.Provid
        }
        if !conf.DisableJSON {
                addMinifier(m, mediaTypes, "json", &conf.Tdewolff.JSON)
-               m.AddRegexp(regexp.MustCompile(`^(application|text)/(x-|ld\+)?json$`), &conf.Tdewolff.JSON)
+               m.AddRegexp(regexp.MustCompile(`^(application|text)/(x-|(ld|manifest)\+)?json$`), &conf.Tdewolff.JSON)
        }
        if !conf.DisableSVG {
                addMinifier(m, mediaTypes, "svg", &conf.Tdewolff.SVG)
index a52f43c8b68528b7eecf9bcf8edffe7c72ae8487..a2ffd7993ab0614360fc9ea6e34022060e0a826c 100644 (file)
@@ -143,6 +143,14 @@ var (
                Rel:         "alternate",
        }
 
+       WebAppManifestFormat = Format{
+               Name:        "WebAppManifest",
+               MediaType:   media.WebAppManifestType,
+               BaseName:    "manifest",
+               IsPlainText: true,
+               Rel:         "manifest",
+       }
+
        RobotsTxtFormat = Format{
                Name:        "ROBOTS",
                MediaType:   media.TextType,
@@ -176,6 +184,7 @@ var DefaultFormats = Formats{
        CSVFormat,
        HTMLFormat,
        JSONFormat,
+       WebAppManifestFormat,
        RobotsTxtFormat,
        RSSFormat,
        SitemapFormat,