Inconsistent builds with Hugo - HELP!

I’m getting inconsistent output in the public directory between builds.

Screen cast: https://www.screencast.com/t/Ap1ZaWDXGHv
Repo: https://github.com/ZurabWeb/diyinstallers
Theme: hugo-fresh

Hugo environment:
.$ hugo env
Hugo Static Site Generator v0.55.6-A5D4C82D2/extended linux/amd64 BuildDate: 2019-05-18T08:08:34Z
GOOS=“linux”
GOARCH=“amd64”
GOVERSION=“go1.12.2”

OS: Ubuntu 18.04 with Windows Subsystem for Linux

What in particular is inconsistent about the build outputs?

1 Like

@zwbetz The output html is correct only sometimes. In particular, as you can see in the screen cast, the about/index.html sometimes shows correct contents (from about.md) but at other times it shows contents of the home page. The only difference is different builds. I can keep rebuilding the application and getting different output html in the public directory.

The hugo-fresh themes single.html template is not correct I believe.

The theme has a baseof.html template but then the single.html template is a complete template anyway. My guess is that you get a race condition where Hugo gets confused what template to use.

Create a new template in layouts/_default/single.html with this content.

{{ define "main" }}

{{ partial "single/single.html" . }}

<!-- Back To Top Button -->
<div id="backtotop"><a href="#"></a></div>

{{ if .Params.sidebar }}
{{ partial "single/sidebar.html" . }}
{{ end }}

{{ end }}

It will then override the copy in themes/hugo-fresh/layouts/_default/single.html.

I would also add metaDataFormat: "yaml" to your config.yaml to make sure Hugo read your front matter correctly.

All your content files end in *.md but have only html in them, no markdown. I suggest you rename them to *.html letting Hugo know there is no markdown.

No @frjo I am afraid that this is not why the original poster has encountered this problem.

@ZurabWeb I cloned your repo locally to debug it.

The first thing I noticed was that once I span the local Hugo server the /about/ page was identical to the index page and it did not correspond to what existed under /content/about/.

The second thing I noticed was that you have made extensive overrides to the hugo-fresh theme.

There is a /layouts/ folder directly under the root of your project with various partials and a redefined baseof.html.

This template is what is causing the problem. When I remove <root-of-the-project>/layouts/_default/baseof.html the /about/ page displays as intended.

I have not looked into the specifics about the reasons why this is caused by your overriden baseof.html template since I do not have the time for this. I suggest that you debug it line by line so that you can find out what is causing the problem you reported.

The overridden based.html only adds a single line, a partial that brings in some JavaScript.

When I override the single.html, as I suggested above, I can consistently build the site correctly. Without it I get the same inconsistent behaviour as mentioned in the question.

1 Like

Thanks for your input. How do you suggest I debug it line-by-line? By adding comments and building the website with hugo in verbose mode? That would really take me too long, since it’s a very slow process. Are there any tools to debug how hugo builds the websites on the fly, such as xdebug for example?

Most of my overrides are small, they’re just in a lot of files. This is my first website I’m creating with JAMstack and hugo, and already experiencing issues I shouldn’t be in the first place. It’s pretty frustrating to be honest and makes a pretty bad impression overall. This was supposed to be a simple, straight forward website with minor overrides of the theme, and this bug is taking two weeks to resolve now. Eh…

Super helpful, THANK YOU! Now the site builds as it should.

I don’t get why it’s still an issue if it’s a known race condition…

Did that, thanks!

I may add some markdown later on, I wouldn’t want to have to rename the files though. The build process doesn’t affect the production performance, so I think I’ll leave it as *.md. Thanks for the suggestion.

Having a baseof.html template tells Hugo that this file always should be the base template.

By then having a complete template in single.html you are asking Hugo to turn left and right at the same time.

Since that is not possible Hugo goes with whatever comes first. What come first differ because Hugo is build for speed and process your pages in parallel.

1 Like

We’ve all been there. It takes time and patience (there are no dedicated debug tools).

However the above comment by @frjo offers a pretty good explanation about the behavior you experienced.

I often check out Hugo’s templates lookup order for reference when overriding or checking out themes: