How to use the new Custom Output Formats

Hi,

I’m trying to use the new Custom Output Format feature.

My hugo version is Hugo Static Site Generator v0.20.3 windows/amd64 BuildDate: 2017-04-24T14:09:50-03:00

I want to generate a .htaccess file
file [hugoroot]/layouts/.htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.com$ [NC]
RewriteRule ^(.*)$ {{ .Site.BaseURL }}/$1 [R=301,L]

In my confing.toml I have added
[mediaTypes]
[mediaTypes.“text/htaccess”]
suffix = “htaccess”

[outputFormats.htaccess]
mediaType = "text/htaccess"
baseName = "txt"
isPlainText = true

I have tried to do almost same thing with robots.txt file
file [hugoroot]/layouts/.htaccess

I didn’t put anything on config.toml file as I understood the text/plain format is already build-in.

But nothing is generated on both cases.

How do I do these two things?

Thanks

  1. You need to name your layout file according to the documentation.
  2. I assume you will currently not be able to have a blank filename (".htaccess"), you could set baseName="", but I suspect it will default to index.
  3. You need to define your new format in a outputs definition.

Hi,

Thanks for your answer. But I still not able to make it work.

I have created a new test project at https://github.com/tutume/hugotests
There, I have the following config.toml

baseurl = "https://domain.com/"
languageCode = "en-us"
title = "Testing Hugo"
theme = “hugo_theme_robust”

[mediaTypes]
[mediaTypes.“text/htaccess”]
suffix = “htaccess”

[outputFormats]
[outputFormats.MyHTA]
mediaType = "text/htaccess"
baseName = ""
isPlainText = true

[outputs]
home = [“HTML”, “MyHTA”]
page = [“HTML”, “MyHTA”]

[Params]
Domain = "domain.com"
Author = “Ricardo Tutume”

and Inside layouts (not theme/layouts) I have
file [apache.MyHTA.htaccess] with
RewriteEngine On
RewriteCond %{HTTP_HOST} ^{{ .Param.Domain }}$ [NC]
RewriteRule ^(.*)$ {{ .Site.BaseURL }}/$1 [R=301,L]

Sorry by my dummy question. But What Am I doing wrong?

I have followed info from

I even tried to use your repo and I cannot see layouts/_default/list.MyEnrichedFormat.enr been generated anywhere.

I’m trying to generate .htaccess and robots.txt as are some basic files that I need, but I will do more things in the future like generating custom php files, etc.

See https://github.com/tutume/hugotests/pull/1

It looks a little surprising that the Output Format name must be lower-cased in the template (please file an issue about that on GitHub), but otherwise it actually works pretty good. I suspected you would have to do some trickery to get .htacess work without the base in the filename, but this worked fine:

http://localhost:1313/.htaccess

Many thanks for the help. It work! Although I didn’t understood how it really works.

Sorry by asking and is there anywhere documented how it exactly works? because at Output Formats docs I couldn’t find anything regarding how to name the template files (like the filename name must have be list.[kind].[suffix])

I will submit the issue regarding the lower-cased template filename.

Anyway, thanks for your help. I will study more how hugo works and maybe I will figure it out.

If you don’t understand the current documentation, I cannot help you (I wrote that, and thought it would be sufficient).

It will probably improve eventually, and it will be easier once the examples pop in the wild.

But I got one tip for you:

Think about how templates are handled and selected for the HTML template type in Hugo (fairly documented). Then apply that logic to another Output Format of choice.

Oh and @tutume – the docs you are linking to is not the official Hugo docs, see https://gohugo.io/extras/output-formats/

@rdwatters – could you make it look less official? Maybe drop the domain and just use the full Netlify URL?

Thanks again for your tip. I have to study more and read about.

For what? Hugodocs.info? I can start using this moving forward if you prefer:

https://hugodocsconcept.netlify.com/

But I’ve been soliciting feedback consistently from the forums and users with the hugodocs.info URL, and there is no real difference in the output formats documentation.

[[EDIT]]
I see the URL you are using, but again, the content is the same…