Custom outputFormat path and _index.md files

I’m trying to set up a “printable” version of my site using output formats:

[mediaTypes]
[mediaTypes."text/html"]
suffixes = ["aspx"]
[mediaTypes.'text/markdown']
suffixes = ['md']
[mediaTypes.'application/json']
suffixes = ['json']


[outputFormats]
[outputFormats.HTML]
mediaType = "text/html"
[outputFormats.JSON]
mediaType = "application/json"
[outputFormats.Markdown]
mediaType = "text/markdown"
isPlainText = true

[outputFormats.Print]
mediaType = "text/html"
baseName = "index"
path = "print"
isHTML = true

[outputs]
home = ["HTML", "Markdown", "Print"]
page = ["HTML", "Markdown", "Print"]
section = ["HTML", "Markdown", "Print"]
term = ["Print"]

It seems to work as expected for most of the pages, except for _index.md pages. Example:

Content Folder:

content/Learn/design-system/Docs
├── datasource
│   ├── datasource_aggregation.md
│   ├── _index.md
│   ├── mappings.md
│   ├── special_variables.md
│   └── variable-subsitution.md
├── _index.md
├── newsletter.md
├── redirect.md
├── search.md
├── sharepoint.md
└── subsites.md

dist/print output: notice the datasource.aspx page is missing

dist/print/learn/design-system/docs
├── datasource
│   ├── datasource_aggregation.aspx
│   ├── mappings.aspx
│   ├── special_variables.aspx
│   └── variable-subsitution.aspx
├── newsletter.aspx
├── redirect.aspx
├── search.aspx
├── sharepoint.aspx
└── subsites.aspx

But if I check the default output, I get this print.aspx file in the “main site” output:

dist/learn/design-system/docs
├── datasource
│   ├── datasource_aggregation.aspx
│   ├── mappings.aspx
│   ├── print.aspx
│   ├── special_variables.aspx
│   └── variable-subsitution.aspx
├── datasource.aspx
├── newsletter.aspx
├── print.aspx
├── redirect.aspx
├── search.aspx
├── sharepoint.aspx
└── subsites.aspx

What i expect is this print.aspx to be called datasource.aspx and located under the print path. (dist/learn/design-system/docs/datasource.aspx)
This seems to happen with all _index.md pages.

Is this intended behavior or maybe a bug?
Thanks!

So you have enabled uglyURLs for all output formats, correct?

Notes:

Reproducible example:

git clone --single-branch -b hugo-forum-topic-55215 https://github.com/jmooring/hugo-testing hugo-forum-topic-55215
cd hugo-forum-topic-55215
rm -rf dist && hugo && tree dist

Thank you for your research and tests!

  • Yes I’m using global uglyURLs
  • I understand there is not much to do from my end right?
  • I’m open to any suggestions on how I could achieve a “printable” version of the site,basically im trying to achieve to have a different layout/partial

I think, disabling the uglyURL for this specific output this could be a ‘good enough’ solution

[outputFormats.print]
mediaType = 'text/html'
baseName = 'print'
noUgly = true
isHTML = true

Not exactly the expected output as before but I can work with it!

dist
├── index.aspx
├── index.md
├── learn
│   ├── design-system
│   │   ├── docs
│   │   │   ├── datasource
│   │   │   │   ├── datasource-aggregation
│   │   │   │   │   └── print.aspx
│   │   │   │   ├── datasource-aggregation.aspx
│   │   │   │   ├── datasource-aggregation.md
│   │   │   │   ├── mappings
│   │   │   │   │   └── print.aspx
│   │   │   │   ├── mappings.aspx
│   │   │   │   ├── mappings.md
│   │   │   │   ├── print.aspx
│   │   │   │   ├── special-variables
│   │   │   │   │   └── print.aspx
│   │   │   │   ├── special-variables.aspx
│   │   │   │   ├── special-variables.md
│   │   │   │   ├── variable-substitution
│   │   │   │   │   └── print.aspx
│   │   │   │   ├── variable-substitution.aspx
│   │   │   │   └── variable-substitution.md
│   │   │   ├── datasource.aspx
│   │   │   ├── datasource.md
│   │   │   ├── newsletter
│   │   │   │   └── print.aspx
│   │   │   ├── newsletter.aspx
│   │   │   ├── newsletter.md
│   │   │   ├── print.aspx
│   │   │   ├── redirect
│   │   │   │   └── print.aspx
│   │   │   ├── redirect.aspx
│   │   │   ├── redirect.md
│   │   │   ├── search
│   │   │   │   └── print.aspx
│   │   │   ├── search.aspx
│   │   │   ├── search.md
│   │   │   ├── sharepoint
│   │   │   │   └── print.aspx
│   │   │   ├── sharepoint.aspx
│   │   │   ├── sharepoint.md
│   │   │   ├── subsites
│   │   │   │   └── print.aspx
│   │   │   ├── subsites.aspx
│   │   │   └── subsites.md
│   │   ├── docs.aspx
│   │   └── docs.md
│   └── print.aspx
├── learn.aspx
├── learn.md
└── print.aspx

Yeah, I think your conclusions are correct. This is a messy problem, and the desired behavior is debatable. Whatever we do will be a breaking change.

I assume your use case is something like:

  1. User visits page
  2. User clicks link to the “printable” version
  3. Use prints the “printable” version

In that scenario, the actual location of the printable version is irrelevant, meaning that the printable version can be adjacent to the web version, or in its own unique path relative to the site root. Does that sound right to you?

I ask because, if we do something about this, we need to pick one or the other.

Yes, that sounds quite right, the main benefit of having the site in a separate folder was it sounded easier to do: post processing, crawling, hide from search, feed to an LLM, ignore from navigation, hide from sitemap, etc.

Now that I think about it… it might be a lot of work!!! :sweat_smile: But I guess i’ll have to do that either way.

Another idea is to have a separate environment / project / build script where I will only build this site version, and then publish it on a different site, and fabricate the “print link” manually on the main site.

That was my first thought.

Which is why I didn’t suggest it (trading one problem for another).

Another thought is to use a different extension for the print media type, removing the need for the path setting in the output format definition. Perhaps the print version doesn’t need to be dynamic, and you could use “html”. Or use “html” and configure the server to interpret as aspx. Or something.

Thank you for your advices! I think I’ll go ahead and continue, with the separate environment/project route.

I do believe the path + uglyURL setting is somehow bugged, I can open a new issue if you like, but I believe this is being tracked already. Let me know.

Thanks for all your help!

Definitely.

See https://github.com/gohugoio/hugo/issues/13829.

This has been resolved in v0.148.0 (to be released later this week). See details:
https://discourse.gohugo.io/t/breaking-changes-in-v0-148-0/55257

1 Like

Ah this is awesome, super fast!!
I went with the new environment approach after all, which worked well.

Thank you for all your efforts!

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.