Custom file extension for HTML output

Hi all,
I have problem with configuration here. I tried to use Media types for change default html extension to .htm, I put this in the config.toml

[mediaTypes]
  [mediaTypes."text/html"]
  suffix = "htm"

But I still get the .html out, with my understanding, the output type for .md files in content directory should be HTML by default. Do I need to config other places?

Many thanks!!!

Did you look at https://gohugo.io/templates/output-formats/#output-formats-for-pages? Seems to fit for your needs, if you want to output in .htm instead of .html.

I will update the docs with this, as this seems to be a common use case.

I have updated the docs to reflect the way it is now. I have, however, discovered some issues that tells me that I may reconsider and simplify this.

1 Like

Thank you vary much, I will follow the issue.

I would suggest you start by following the updated documentation.

Hugo version v0.30.2

with updated document in confilg.toml I added

[mediaTypes]
[mediaTypes."text/html"]
suffix = "htm"

# Redefine HTML to update its media type.
[outputFormats.HTML]
mediaType = "text/html"

this time, it not have any content exported except xml files. I also added…

disableKinds = ["home"]
[outputs]
  page = ["HTML"]

now only one sitemap.xml came out.

This is my directory tree:

β”œβ”€β”€ archetypes
β”‚   └── default.md
β”œβ”€β”€ config.toml
β”œβ”€β”€ content
β”‚   └── about.md
β”œβ”€β”€ data
β”œβ”€β”€ layouts
β”‚   └── _default
β”‚       └── single.html
β”œβ”€β”€ static
└── themes

I suspect you have some invalid TOML, but it is impossible for me to see without the full source.

this is all in my config file just only minimum setting…

baseURL = "http://example.org/"
languageCode = "en-us"
title = "My New Hugo Site"
disableKinds = ["home"]

[mediaTypes]
[mediaTypes."text/html"]
suffix = "htm"

# Redefine HTML to update its media type.
[outputFormats.HTML]
mediaType = "text/html"

[outputs]
  page = ["HTML"]

I have updated the docs. I was a little bit fast in my β€œcopy-paste” from my test.

I may doing something wrong, it still not working.
I have go back to start from the beginning by these steps.

# Hugo Static Site Generator v0.30.2
$ hugo new site ext-test
$ cd ext-test
$ hugo new about.md

add a bit content to ./content/about.md then create file ./layout/_default/single.html with this simple html code

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Document</title>
</head>
<body>
  {{ .Content }}
</body>
</html>

this is the config.toml file

baseURL = "http://example.org/"
languageCode = "en-us"
title = "My New Hugo Site"
[mediaTypes]
  [mediaTypes."text/html"]
  suffix = "htm"

# Redefine HTML to update its media type.
[outputFormats]
  [outputFormats.HTML]
  mediaType = "text/html"

finally hugo -D and this is the final output:

β”œβ”€β”€ archetypes
β”‚   └── default.md
β”œβ”€β”€ config.toml
β”œβ”€β”€ content
β”‚   └── about.md
β”œβ”€β”€ data
β”œβ”€β”€ layouts
β”‚   └── _default
β”‚       └── single.html
β”œβ”€β”€ public
β”‚   β”œβ”€β”€ categories
β”‚   β”‚   └── index.xml
β”‚   β”œβ”€β”€ index.xml
β”‚   β”œβ”€β”€ sitemap.xml
β”‚   └── tags
β”‚       └── index.xml
β”œβ”€β”€ static
└── themes

it is not has ./public/about/index.htm file

If you can share a link to the full source, I can have a look at it. Looking at small snippets isn’t helping, obviously.

I have created a github repo for full source code here…

Thanks for your time.

I notice you have draft = β€œfalse” in your about.md contact page, I think this must be a typo. :slight_smile:

oh that my bad, fixed, thank you :slight_smile:

With this current setup it’s still not export .htm file…

I tried this. But I don’t get it. Do you need to make both config files? I did. And that still didn’t function how explained. Can you explain more simple what is required to make the custom extensions function? Thanks!