Hi there, long time user, first time poster…
I’m confused on how I should use baseURL.
I used Hugo to build a 2000+ page website which has been very well received (people can’t believe there’s no database stuff going on!). It sits at the top of its domain, and so I had baseURL pointing to the domain.
I’ve now moved it under an official directory structure, and modified the baseURL accordingly. The site is now working fine, but in doing the move, I’ve found that I don’t understand how baseURL works at all - to get things to work, I had to replace .Site.BaseURL with my own creation .Site.Params.mybaseurl - ugly :(.
I’m using the latest Hugo, Hugo Static Site Generator v0.40.3 darwin/amd64 BuildDate: and have built a barebones site to try this out.
config.toml:
baseURL = "http://anexample.org/"
languageCode = "en-us"
title = "My New Hugo Site, using anexample.org"
theme = "simple"
I deliberately chose http://anexample.org as I thought using example.org might trigger some internal code.
The ‘theme’ simple, is something I built just to test things, the file at themes/simple/layouts/_default/single.html is just this (literally, I removed the html boilerplate):
<h1>single.html</h1>
.Site.Title: {{ .Site.Title }} <br>
.Site.BaseURL: {{ .Site.BaseURL }} <br>
{{ .Content }}
I then created a page $ hugo new post/start.md and put some content in it (flipped draft to false, and put ‘Hello World’ in). When I navigate to http://localhost:1313/post/start/ this is what I see;
single.html
.Site.Title: My New Hugo Site, using anexample.org
.Site.BaseURL: http://localhost:1313/
Hello World
It seems that the output .Site.BaseURL bears no relation to the value in config.toml?
I also found that the case of the parameter in the template is really important. You’ll see that the template is using .Site.BaseURL whilst config.toml is baseURL - that works (but the .Site.BaseURL still doesn’t show the value in config.toml. I changed the parameter in config.toml to be baseurl = "http://anexample.org/" and the site still showed output.
What didn’t work though, is changing the case in the template, if I edit simple.html like this, the site won’t build;
<h1>single.html</h1>
.Site.Title: {{ .Site.Title }} <br>
.Site.BaseURL: {{ .Site.BaseURL }} <br>
Lowercase
.Site.baseurl {{ .Site.baseurl }} <br>
{{ .Content }}
and gives this error;
ERROR 2018/05/24 11:09:41 Error while rendering "page" in "post/": template: theme/_default/single.html:6:26: executing "theme/_default/single.html" at <.Site.baseurl>: can't evaluate field baseurl in type *hugolib.SiteInfo
Can anyone shed some light on this? I’m grateful things are working with my dreadful kludge, but I suspect I’m missing something pretty fundamental here. Also, any clarification on the ‘casedness’ of parameters in config.toml would be appreciated!
many thanks,
Tone.