diff options
Diffstat (limited to 'resources')
-rw-r--r-- | resources/images/image.go | 2 | ||||
-rw-r--r-- | resources/page/page_paths.go | 11 | ||||
-rw-r--r-- | resources/page/page_paths_test.go | 11 | ||||
-rw-r--r-- | resources/postpub/fields_test.go | 11 | ||||
-rw-r--r-- | resources/resource_spec.go | 4 |
5 files changed, 19 insertions, 20 deletions
diff --git a/resources/images/image.go b/resources/images/image.go index 3d28263c0..b71321244 100644 --- a/resources/images/image.go +++ b/resources/images/image.go @@ -265,7 +265,7 @@ func (f Format) SupportsTransparency() bool { // DefaultExtension returns the default file extension of this format, starting with a dot. // For example: .jpg for JPEG func (f Format) DefaultExtension() string { - return f.MediaType().FullSuffix() + return f.MediaType().FirstSuffix.FullSuffix } // MediaType returns the media type of this image, e.g. image/jpeg for JPEG diff --git a/resources/page/page_paths.go b/resources/page/page_paths.go index fc576f05a..3d34866d1 100644 --- a/resources/page/page_paths.go +++ b/resources/page/page_paths.go @@ -128,6 +128,7 @@ func CreateTargetPaths(d TargetPathDescriptor) (tp TargetPaths) { } pagePath := slash + fullSuffix := d.Type.MediaType.FirstSuffix.FullSuffix var ( pagePathDir string @@ -172,7 +173,7 @@ func CreateTargetPaths(d TargetPathDescriptor) (tp TargetPaths) { hasSlash := strings.HasSuffix(d.URL, slash) if hasSlash || !hasDot { - pagePath = pjoin(pagePath, d.Type.BaseName+d.Type.MediaType.FullSuffix()) + pagePath = pjoin(pagePath, d.Type.BaseName+fullSuffix) } else if hasDot { pagePathDir = path.Dir(pagePathDir) } @@ -229,9 +230,9 @@ func CreateTargetPaths(d TargetPathDescriptor) (tp TargetPaths) { linkDir = pagePathDir if isUgly { - pagePath = addSuffix(pagePath, d.Type.MediaType.FullSuffix()) + pagePath = addSuffix(pagePath, fullSuffix) } else { - pagePath = pjoin(pagePath, d.Type.BaseName+d.Type.MediaType.FullSuffix()) + pagePath = pjoin(pagePath, d.Type.BaseName+fullSuffix) } if !isHtmlIndex(pagePath) { @@ -267,9 +268,9 @@ func CreateTargetPaths(d TargetPathDescriptor) (tp TargetPaths) { linkDir = pagePathDir if base != "" { - pagePath = path.Join(pagePath, addSuffix(base, d.Type.MediaType.FullSuffix())) + pagePath = path.Join(pagePath, addSuffix(base, fullSuffix)) } else { - pagePath = addSuffix(pagePath, d.Type.MediaType.FullSuffix()) + pagePath = addSuffix(pagePath, fullSuffix) } if !isHtmlIndex(pagePath) { diff --git a/resources/page/page_paths_test.go b/resources/page/page_paths_test.go index ab7164f46..28937899f 100644 --- a/resources/page/page_paths_test.go +++ b/resources/page/page_paths_test.go @@ -27,8 +27,7 @@ import ( func TestPageTargetPath(t *testing.T) { pathSpec := newTestPathSpec() - noExtNoDelimMediaType := media.TextType - noExtNoDelimMediaType.Suffixes = []string{} + noExtNoDelimMediaType := media.WithDelimiterAndSuffixes(media.TextType, "", "") noExtNoDelimMediaType.Delimiter = "" // Netlify style _redirects @@ -209,11 +208,11 @@ func TestPageTargetPath(t *testing.T) { // TODO(bep) simplify if test.d.Kind == KindPage && test.d.BaseName == test.d.Type.BaseName { } else if test.d.Kind == KindHome && test.d.Type.Path != "" { - } else if test.d.Type.MediaType.Suffix() != "" && (!strings.HasPrefix(expected.TargetFilename, "/index") || test.d.Addends != "") && test.d.URL == "" && isUgly { + } else if test.d.Type.MediaType.FirstSuffix.Suffix != "" && (!strings.HasPrefix(expected.TargetFilename, "/index") || test.d.Addends != "") && test.d.URL == "" && isUgly { expected.TargetFilename = strings.Replace(expected.TargetFilename, - "/"+test.d.Type.BaseName+"."+test.d.Type.MediaType.Suffix(), - "."+test.d.Type.MediaType.Suffix(), 1) - expected.Link = strings.TrimSuffix(expected.Link, "/") + "." + test.d.Type.MediaType.Suffix() + "/"+test.d.Type.BaseName+"."+test.d.Type.MediaType.FirstSuffix.Suffix, + "."+test.d.Type.MediaType.FirstSuffix.Suffix, 1) + expected.Link = strings.TrimSuffix(expected.Link, "/") + "." + test.d.Type.MediaType.FirstSuffix.Suffix } diff --git a/resources/postpub/fields_test.go b/resources/postpub/fields_test.go index 10a68ac5a..19c3720f7 100644 --- a/resources/postpub/fields_test.go +++ b/resources/postpub/fields_test.go @@ -31,15 +31,14 @@ func TestCreatePlaceholders(t *testing.T) { }) c.Assert(m, qt.DeepEquals, map[string]interface{}{ - "FullSuffix": "pre_foo.FullSuffix_post", "IsZero": "pre_foo.IsZero_post", - "Type": "pre_foo.Type_post", - "MainType": "pre_foo.MainType_post", - "Delimiter": "pre_foo.Delimiter_post", "MarshalJSON": "pre_foo.MarshalJSON_post", + "Suffixes": "pre_foo.Suffixes_post", + "Delimiter": "pre_foo.Delimiter_post", + "FirstSuffix": "pre_foo.FirstSuffix_post", "String": "pre_foo.String_post", - "Suffix": "pre_foo.Suffix_post", + "Type": "pre_foo.Type_post", + "MainType": "pre_foo.MainType_post", "SubType": "pre_foo.SubType_post", - "Suffixes": "pre_foo.Suffixes_post", }) } diff --git a/resources/resource_spec.go b/resources/resource_spec.go index dc13d16d9..156def363 100644 --- a/resources/resource_spec.go +++ b/resources/resource_spec.go @@ -268,10 +268,10 @@ func (r *Spec) newResource(sourceFs afero.Fs, fd ResourceSourceDescriptor) (reso } ext := strings.ToLower(filepath.Ext(fd.RelTargetFilename)) - mimeType, found := r.MediaTypes.GetFirstBySuffix(strings.TrimPrefix(ext, ".")) + mimeType, suffixInfo, found := r.MediaTypes.GetFirstBySuffix(strings.TrimPrefix(ext, ".")) // TODO(bep) we need to handle these ambiguous types better, but in this context // we most likely want the application/xml type. - if mimeType.Suffix() == "xml" && mimeType.SubType == "rss" { + if suffixInfo.Suffix == "xml" && mimeType.SubType == "rss" { mimeType, found = r.MediaTypes.GetByType("application/xml") } |