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
This commit is contained in:
Bjørn Erik Pedersen 2018-07-10 11:55:22 +02:00
parent 4108705934
commit b874a1ba7a
20 changed files with 318 additions and 127 deletions

View file

@ -179,7 +179,7 @@ Len Pages: {{ .Kind }} {{ len .Site.RegularPages }} Page Number: {{ .Paginator.P
th.assertFileContent("public/index.html",
// The HTML entity is a deliberate part of this test: The HTML templates are
// parsed with html/template.
`List HTML|JSON Home|<atom:link href=http://example.com/blog/ rel="self" type="text/html&#43;html" />`,
`List HTML|JSON Home|<atom:link href=http://example.com/blog/ rel="self" type="text/html" />`,
"en: Elbow",
"ShortHTML",
"OtherShort: <h1>Hi!</h1>",
@ -195,7 +195,7 @@ Len Pages: {{ .Kind }} {{ len .Site.RegularPages }} Page Number: {{ .Paginator.P
th.assertFileContent("public/index.json",
"Output/Rel: JSON/canonical|",
// JSON is plain text, so no need to safeHTML this and that
`<atom:link href=http://example.com/blog/index.json rel="self" type="application/json+json" />`,
`<atom:link href=http://example.com/blog/index.json rel="self" type="application/json" />`,
"ShortJSON",
"OtherShort: <h1>Hi!</h1>",
)