From ba1d0051b44fdd242b20899e195e37ab26501516 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Thu, 11 Mar 2021 09:18:01 +0100 Subject: media: Make Type comparable So we can use it and output.Format as map key etc. This commit also fixes the media.Type implementation so it does not need to mutate itself to handle different suffixes for the same MIME type, e.g. jpg vs. jpeg. This means that there are no Suffix or FullSuffix on media.Type anymore. Fixes #8317 Fixes #8324 --- hugolib/config_test.go | 10 ++++++---- hugolib/pagebundler_test.go | 4 +--- hugolib/site.go | 2 +- hugolib/site_output_test.go | 3 ++- 4 files changed, 10 insertions(+), 9 deletions(-) (limited to 'hugolib') diff --git a/hugolib/config_test.go b/hugolib/config_test.go index aeeee5fa5..ecb450067 100644 --- a/hugolib/config_test.go +++ b/hugolib/config_test.go @@ -220,8 +220,9 @@ map[string]interface {}{ MainType: "text", SubType: "m1", Delimiter: ".", - Suffixes: []string{ - "m1main", + FirstSuffix: SuffixInfo{ + Suffix: "m1main", + FullSuffix: ".m1main", }, }, }, @@ -231,8 +232,9 @@ map[string]interface {}{ MainType: "text", SubType: "m2", Delimiter: ".", - Suffixes: []string{ - "m2theme", + FirstSuffix: SuffixInfo{ + Suffix: "m2theme", + FullSuffix: ".m2theme", }, }, }, diff --git a/hugolib/pagebundler_test.go b/hugolib/pagebundler_test.go index fc02d5857..7d775871a 100644 --- a/hugolib/pagebundler_test.go +++ b/hugolib/pagebundler_test.go @@ -34,8 +34,6 @@ import ( "github.com/gohugoio/hugo/htesting" - "github.com/gohugoio/hugo/media" - "github.com/gohugoio/hugo/deps" "github.com/spf13/viper" @@ -76,7 +74,7 @@ func TestPageBundlerSiteRegular(t *testing.T) { cfg.Set("outputFormats", map[string]interface{}{ "CUSTOMO": map[string]interface{}{ - "mediaType": media.HTMLType, + "mediaType": "text/html", "baseName": "cindex", "path": "cpath", "permalinkable": true, diff --git a/hugolib/site.go b/hugolib/site.go index d2a5e68ae..3c7c03bd1 100644 --- a/hugolib/site.go +++ b/hugolib/site.go @@ -913,7 +913,7 @@ type whatChanged struct { // package, so it will behave correctly with Hugo's built-in server. func (s *Site) RegisterMediaTypes() { for _, mt := range s.mediaTypesConfig { - for _, suffix := range mt.Suffixes { + for _, suffix := range mt.Suffixes() { _ = mime.AddExtensionType(mt.Delimiter+suffix, mt.Type()+"; charset=utf-8") } } diff --git a/hugolib/site_output_test.go b/hugolib/site_output_test.go index 5a329942c..1961dd06f 100644 --- a/hugolib/site_output_test.go +++ b/hugolib/site_output_test.go @@ -305,13 +305,14 @@ baseName = "customdelimbase" c.Assert(err, qt.IsNil) + s := h.Sites[0] + th.assertFileContent("public/_redirects", "a dotless") th.assertFileContent("public/defaultdelimbase.defd", "default delimim") // This looks weird, but the user has chosen this definition. th.assertFileContent("public/nosuffixbase", "no suffix") th.assertFileContent("public/customdelimbase_del", "custom delim") - s := h.Sites[0] home := s.getPage(page.KindHome) c.Assert(home, qt.Not(qt.IsNil)) -- cgit v1.2.3