Using OutputFormats to generate config.yml in a certain section?

I’m looking to achieve the following output in my build:

public/
├── admin/
│   ├── index.html
│   └── config.yml
...

…where config.yml is dynamically generated via a custom output format.

So far, I’ve tried to achieve this with the following content structure:

content/
├── admin/
│   ├── _index.md
│   └── config.md
layouts/
├── admin/
│   ├── admin.html
│   └── single.adminconfigyaml.yml
...

hugo.toml:

[outputFormats]
  [outputFormats.AdminConfigYaml]
    baseName = 'config'
    isPlainText = true
    mediaType = 'application/yaml'

_/content/admin/index.md:

+++
title = "Admin"
+++

/content/admin/config.md:

+++
title = 'Config'
outputs = ['AdminConfigYaml']
+++

The index.html builds just fine, but I get a warning regarding the config file:

WARN  found no layout file for "adminconfigyaml" for kind "page": You should create a template file which matches Hugo Layouts Lookup Rules for this combination.

It seems to me that, for the purposes of Hugo’s template lookup order, content/admin/config.md would be a single page in “admin” section with OutputFormat AdminConfigYaml and suffix yml, in which case the filename layouts/admin/single.adminconfigyaml.yml should work.

Any ideas where I went wrong?

Demo Repo

For those who are curious, my goal is to dynamically generate the config file for Sveltia, a drop-in replacement for Decap CMS (formerly Netlify CMS).

Update: I’ve discovered the issue.

I renamed the template file from single.adminconfigyaml.yml to single.adminconfig.yaml, and the build worked as expected.

Unfortunately, that still didn’t help me because the resulting output file was config.yaml, and my admin backend expects it to have the .yml extension.

To solve this, I tried redefining the application/yaml media type in my Hugo config, as follows:

[mediaTypes]
  [mediaTypes.'application/yaml']
    suffixes = ['yaml', 'yml']

This still did not work. So I switched the order of the suffixes in the config:

[mediaTypes]
  [mediaTypes.'application/yaml']
    suffixes = ['yml', 'yaml']

This worked! Which is great, but it got me curious, so I tried renaming the template again to use the .yaml suffix. This time, I got the same warning about a missing layout file.

So it appears that, in cases where multiple suffixes are specified for the mediaType, Hugo only acknowledges the first one.

@bep is this a bug?

No it isn’t. The media type definitions are used for a lot of “things” inside Hugo. We have multiple suffixes fo help going from filename => media type. The layout logic uses the first suffix. You could argue that we should try all of them, but it’s not a bug, it was deliberate to simplify the implementation.

Understood. Although the docs could be clearer on this point, especially since the media types are listed on the Output Formats docs page.

Should I go ahead and file a PR to update the docs?