Issue with /projects/ and content type generating

Hi all,

I’m currently using Hugo 0.54.0, but the issue happened on older versions too.

I’ve got a problem with template generation. Content lives under the /projects/ folder both for data and inside theme layouts folder. Structure looks something like that:

content/projects/project1.md
content/projects/project2.md
content/projects/project3.md

themes/mytheme/layouts/projects/list.html (standard listing under /projects/)
themes/mytheme/layouts/projects/taxonomy.html (category page, dynamic code is the same as in list.html)
themes/mytheme/layouts/projects/single.html (single project)

And the example .md file from project

+++
date = "2019-03-19T00:00:00+00:00"
excerpt = "Second Project Excerpt"
projects = ["cat1", "cat2"]
thumb = "/uploads/photo-1511707171634-5f897ff02aa9-small.jpg"
thumb_big = "/uploads/photo-1511707171634-5f897ff02aa9.jpg"
title = "Second Project"

+++
This is content for my second project

The problem is that sometimes when I build new site with Hugo the /projects/ page is getting messed up and instead of projects categories are generated and instead of links to single project links to single categories. Below are the screens from properly generated page and the issue. This doesn’t happen every time, but still I have to check the site after deploy every time to make sure it’s all good.

And lastly this is how list/taxonomy.html file looks like. Both are practically the same, only the main title is different.

{{ define "main" }}
<div class="page-title">
  <div class="container">
    <h1>{{ .Title }}</h1>
  </div>
</div>
<div class="container py-5">
  <div class="row">
    {{ range .Pages }}
    <div class="col-md-4">
      <article class="card mb-5">
        {{ $title := .Title }}
        {{ $permalink := .Permalink }}
        {{ with .Params.thumb }}
        <a href="{{ $permalink }}">
          <img class="card-img-top" src="{{ . | urlize | relURL }}" alt="{{ $title }}">
        </a>
        {{ end }}
        <div class="card-body">
          <a href="{{ $permalink }}">
            <h5 class="card-title">{{ $title }}</h5>
          </a>
          {{ with .Params.excerpt }}
            <p class="card-text">{{ . }}</p>
          {{ end }}
          <a href="{{ $permalink }}" class="btn btn-primary btn-sm">More details</a>
        </div>
        <div class="card-footer">
          {{ range .Params.projects }}
            <a class="btn btn-secondary btn-sm" href="{{ "/projects/" | relLangURL }}{{ . | urlize }}">{{ . }}</a>
          {{ end }}
        </div>
      </article>
    </div><!-- .col -->
    {{ end }}
  </div><!-- .row -->
</div><!-- .container -->
{{ end }}

My question is: what is wrong here and why it is generated like that sometimes? Code in my example seems to be pretty basic, I wanted to keep it simple. The issue doesn’t happen every time, but sometimes I need to rebuild the site couple times to make it work.

Any ideas? Maybe there is as issue in the code somewhere or maybe that’s known bug and how Hugo works?

Thanks for any help
Cheers

Welcome on the Hugo forum! :wave:

It’s hard to tell what’s going on here since your template code looks right. Can it be that your content files miss certain parameters?

For example, the ‘bad example’ misses the thumb images. But your code only add those when thumb is set:

{{ with .Params.thumb }}
<a href="{{ $permalink }}">
  <img class="card-img-top" src="{{ . | urlize | relURL }}" alt="{{ $title }}">
</a>
{{ end }}

You probably already looked at this, but without looking at the site’s code I can’t come up with something more helpful. Perhaps someone else has a better idea. :slight_smile:

It’s at least definitely not how Hugo works: given the same input Hugo always renders the same output.

Hi Jura,

thanks for the response.

All parameters are provided, so that can’t be the issue. Tested with and without, problem was still there.

Cheers

What does your config.toml look like? I notice you have

projects = ["cat1", "cat2"]

in your sample front matter. Are you using projects as a taxonomy? If so, that might be the issue.

Hi,

here is the code from config.toml:

baseURL = "mysite.com"
languageCode = "en-us"
theme = "mytheme"
title = "My New Hugo Site"
[[menu.primary]]
name = "All fields"
url = "/all-fields/"
weight = 5
[[menu.primary]]
name = "Contact"
url = "/contact/"
weight = 4
[[menu.primary]]
identifier = "home"
name = "Homepage"
url = "/"
weight = 1
[[menu.primary]]
identifier = "posts"
name = "Posts"
url = "/posts/"
weight = 2
[[menu.primary]]
identifier = "projects"
name = "Projects"
url = "/projects/"
weight = 3
[taxonomies]
category = "categories"
project = "projects"
service = "services"
tag = "tags"

Due to the official docs all seems to be fine with the taxonomies (https://gohugo.io/content-management/taxonomies/), but you never know. It also happens once in a while, it’s not permanent issue, sometimes /projects/ are generated properly, but sometime I need to trigger the build once again.

File indentation is “flat”, because it’s generated from Forestry, but it doesn’t change/fix/break anything. Tested that too.

Well, you have to choose if /projects/ is supposed to be a section or a taxonomy term. It can’t be both.

Ok, so basically if I want to keep the taxonomy term as project = "projects" I need to change the section to something else e.g.

content/portfolio/project1.md
content/portfolio/project2.md
content/portfolio/project3.md

themes/mytheme/layouts/portfolio/list.html
themes/mytheme/layouts/portfolio/taxonomy.html
themes/mytheme/layouts/portfolio/single.html

Both can’t be the same?

OR MAYBE

changing tax terms to project-cat = "project-cats" ?

Yep. Either of those options should work. your Taxonomy layout also needs to go in a different place, depending on what your taxonomy ends up being called: https://gohugo.io/templates/lookup-order/

Ok, got it. I’ll check it out.

Thanks :slight_smile: