Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-07-10 12:55:22 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2018-07-10 23:13:52 +0300
commitb874a1ba7ab8394dc741c8c70303a30a35b63e43 (patch)
tree756a5869cf623ace8387fcf6166a831c052f0ae7 /resource
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')
-rw-r--r--resource/bundler/bundler.go2
-rw-r--r--resource/minifiers/minify.go2
-rw-r--r--resource/resource.go5
-rw-r--r--resource/resource_test.go2
4 files changed, 5 insertions, 6 deletions
diff --git a/resource/bundler/bundler.go b/resource/bundler/bundler.go
index 2f3981485..a86b39efa 100644
--- a/resource/bundler/bundler.go
+++ b/resource/bundler/bundler.go
@@ -70,7 +70,7 @@ func (c *Client) Concat(targetPath string, resources []resource.Resource) (resou
// The given set of resources must be of the same Media Type.
// We may improve on that in the future, but then we need to know more.
for i, r := range resources {
- if i > 0 && r.MediaType() != resolvedm {
+ if i > 0 && r.MediaType().Type() != resolvedm.Type() {
return nil, errors.New("resources in Concat must be of the same Media Type")
}
resolvedm = r.MediaType()
diff --git a/resource/minifiers/minify.go b/resource/minifiers/minify.go
index 609b9a694..604ac6f8c 100644
--- a/resource/minifiers/minify.go
+++ b/resource/minifiers/minify.go
@@ -45,7 +45,7 @@ func New(rs *resource.Spec) *Client {
addMinifierFunc(m, mt, "text/html", "html", html.Minify)
addMinifierFunc(m, mt, "application/javascript", "js", js.Minify)
addMinifierFunc(m, mt, "application/json", "json", json.Minify)
- addMinifierFunc(m, mt, "image/svg", "xml", svg.Minify)
+ addMinifierFunc(m, mt, "image/svg+xml", "svg", svg.Minify)
addMinifierFunc(m, mt, "application/xml", "xml", xml.Minify)
addMinifierFunc(m, mt, "application/rss", "xml", xml.Minify)
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(
diff --git a/resource/resource_test.go b/resource/resource_test.go
index 659994c36..e699e6f3f 100644
--- a/resource/resource_test.go
+++ b/resource/resource_test.go
@@ -97,7 +97,7 @@ func TestNewResourceFromFilenameSubPathInBaseURL(t *testing.T) {
}
-var pngType, _ = media.FromString("image/png")
+var pngType, _ = media.FromStringAndExt("image/png", "png")
func TestResourcesByType(t *testing.T) {
assert := require.New(t)