Different outputs with the same media type in Hugo


#1

I have got this issue and thought about posting it here too.

In my hugo site I need to serve an index file that is generated from a template called index.json. I also need to generate another file from a template called lastmod.json

So, following the documentation I came up with this config, which does not work. When accessing lastmod.json instead of giving me the content of its template, the content of the first template is rendered instead.

[outputFormats.JSON-index]
    baseName = "index"
    isPlainText = true
    mediaType = "application/json"
    notAlternative = true


[outputFormats.JSON-lastmod]
    baseName = "lastmod"
    isPlainText = true
    mediaType = "application/json"
    notAlternative = true

What this leads me to believe is that you can only create one output format for every mediaType because if I use this configuration it works without any problems. But I wanted to have both files with the json extension.

[outputFormats.JSON-index]
    baseName = "index"
    isPlainText = true
    mediaType = "application/json"
    notAlternative = true

[outputFormats.JSON-lastmod]
    baseName = "index"
    isPlainText = true
    mediaType = "application/lastmod"
    notAlternative = true

[mediaTypes]
    [mediaTypes."application/lastmod"]
        suffix = "lastmod"

Is it possible to make both files end in .json? Thanks in advance.


#2

Bump!


#3

I simply set the url variable in the front matter of the custom outputs for that:

+++
outputs = ["SectionRSS"]
url     = "/platform/rss.xml"
layout  = "section-rss"
+++

I never succeeded in doing it another way from what I can recall, so also unfortunately can’t help much more with the approach you’re trying here.