summaryrefslogtreecommitdiffstats
path: root/resource/resource.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-07-10 11:55:22 +0200
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-07-10 22:13:52 +0200
commitb874a1ba7ab8394dc741c8c70303a30a35b63e43 (patch)
tree756a5869cf623ace8387fcf6166a831c052f0ae7 /resource/resource.go
parent4108705934846f2b7cae2602ce14aeee17139608 (diff)
media: Allow multiple file suffixes per media type
Before this commit, `Suffix` on `MediaType` was used both to set a custom file suffix and as a way to augment the mediatype definition (what you see after the "+", e.g. "image/svg+xml"). This had its limitations. For one, it was only possible with one file extension per MIME type. Now you can specify multiple file suffixes using "suffixes", but you need to specify the full MIME type identifier: [mediaTypes] [mediaTypes."image/svg+xml"] suffixes = ["svg", "abc ] In most cases, it will be enough to just change: [mediaTypes] [mediaTypes."my/custom-mediatype"] suffix = "txt" To: [mediaTypes] [mediaTypes."my/custom-mediatype"] suffixes = ["txt"] Hugo will still respect values set in "suffix" if no value for "suffixes" is provided, but this will be removed in a future release. Note that you can still get the Media Type's suffix from a template: {{ $mediaType.Suffix }}. But this will now map to the MIME type filename. Fixes #4920
Diffstat (limited to 'resource/resource.go')
-rw-r--r--resource/resource.go5
1 files changed, 2 insertions, 3 deletions
diff --git a/resource/resource.go b/resource/resource.go
index f0989e51e..a7a9cb878 100644
--- a/resource/resource.go
+++ b/resource/resource.go
@@ -416,16 +416,15 @@ func (r *Spec) newResource(sourceFs afero.Fs, fd ResourceSourceDescriptor) (Reso
mimeType, found := r.MediaTypes.GetFirstBySuffix(strings.TrimPrefix(ext, "."))
// TODO(bep) we need to handle these ambigous types better, but in this context
// we most likely want the application/xml type.
- if mimeType.Suffix == "xml" && mimeType.SubType == "rss" {
+ if mimeType.Suffix() == "xml" && mimeType.SubType == "rss" {
mimeType, found = r.MediaTypes.GetByType("application/xml")
}
if !found {
mimeStr := mime.TypeByExtension(ext)
if mimeStr != "" {
- mimeType, _ = media.FromString(mimeStr)
+ mimeType, _ = media.FromStringAndExt(mimeStr, ext)
}
-
}
gr := r.newGenericResourceWithBase(