I’m adding an Atom feed, for which the spec says:
An Atom Document, when serialized as XML 1.0, can be identified with
the following media type:
MIME media type name: application
MIME subtype name: atom+xml
However, when I put a plus in the config:
[mediaTypes."application/atom+xml"]
suffix = "xml"
Sadly Hugo doesn’t like the plus:
ERROR 2018/05/21 17:40:05 media type keys cannot contain any '+' chars. Valid example is "text/css"
Is there some other way to get it to allow the plus in the media type name? I tried adding a string
variable, but it was ignored.
You can template your rel="alternate"
like this – Set .MediaType.Type
to "atom"
and .MediaType.Suffix
to "xml"
… which would be the case anyways.
So define your custom output formats using something like this (I do exactly that):
[mediaTypes]
[mediaTypes."application/atom"]
suffix = "xml"
[outputFormats.Atom]
mediaType = "application/atom"
baseName = "atom" # generated file = <baseName>.<mediaType."application/atom".suffix> = atom.xml
isPlainText = false
[outputs]
home = ["HTML", "RSS", "ATOM"] # default = ["HTML", "RSS"]
Ah, Just use the suffix, got it. I’ve written it as:
{{ range .AlternativeOutputFormats -}}
<link rel="{{ .Rel }}" type="{{ .MediaType.Type }}{{ if eq .MediaType.Suffix "xml" }}+xml{{ end }}" href="{{ .Permalink | safeURL }}" title="{{ $.Site.Title }}" />
{{ end }}
Which works just as I need. Thanks!