Hugo

Built website different on local and on Netlify

Hello there !
I am a newbie here, and I try to do my first Hugo website but I face the same problem since 5 hours. I’m quite desperate and hope you will help me to find the problem.
I run Hugo v.0.58.2 on macOS and push my local folder through GitLab to Netlify.
I just followed the 101 Slowstart after trying many other sources, but I still meet the same problem.
I just did everything like the 101 Slowstart guide, and just added a “_default/single.html” because Hugo said many errors :

Building sites … WARN 2019/09/14 03:15:52 found no layout file for “HTML” for “page”: You should create a template file which matches Hugo Layouts Lookup Rules for this combination.

WARN 2019/09/14 03:15:52 found no layout file for “HTML” for “page”: You should create a template file which matches Hugo Layouts Lookup Rules for this combination.

WARN 2019/09/14 03:15:52 found no layout file for “HTML” for “page”: You should create a template file which matches Hugo Layouts Lookup Rules for this combination.

WARN 2019/09/14 03:15:52 found no layout file for “HTML” for “page”: You should create a template file which matches Hugo Layouts Lookup Rules for this combination.

WARN 2019/09/14 03:15:52 found no layout file for “HTML” for “page”: You should create a template file which matches Hugo Layouts Lookup Rules for this combination.

WARN 2019/09/14 03:15:52 found no layout file for “HTML” for “page”: You should create a template file which matches Hugo Layouts Lookup Rules for this combination.

The code I put in the _default/single.html is the exact same as posts/single.html and articles/single.html

Well, the folder built on my mac displays something different than the netlify built.
The first is on my netlify, the second is on my mac. The first displays the third post and the third article, and the second displays the two categories (“Posts” and “Articles” are the folder’s names), but the code is the same !
I just don’t get it. There’s so much to understand with this Hugo system, and I can’t get the same output, and the difference is so huge !

Here’s the code (layouts/index.html) :

    <!-- this section is populated by pulling posts from the site -->
    {{ range first 1 (where .Pages.ByPublishDate.Reverse "Section" "posts") }}
        <article>
            <header>
            <h2>{{ .Title }}</h2>
            <p><time datetime="{{.Date}}">{{ .Date.Format "Mon, Jan 2, 2006" }}</time></p>
            </header>
            {{ .Summary }}
            <nav>
            <ul>
                <li><a href="{{ .RelPermalink }}">Read More &raquo;</a></li>
            </ul>
            </nav>
        </article>
    {{ end }}
    <footer>
    <a href="{{ "posts/" | absURL }}">All posts...</a>
    </footer>
</section>```

Thanks... I'm desperate :(

Could you post a link to your GitLab repository? Without that, we’re limited in how much we can help.

My guess is there are two problems:

  1. You haven’t set the baseURL value correctly in your config file.
  2. There’s something wrong with the theme you’re using. Are you using a theme from the directory, or have you built your own? Have you used sub-modules for the theme?

Ok, it appears .Pages gets the folders when on the local server and the files inside the folders when on Netlify (I just figured that by trying .Site.Pages instead of .Pages. I still don’t get it but there’s now a clue !

Here’s my GitLab repo

No theme at all, no sub-modules, just from scratch following the 101 guide.

{{ range (where .Site.Pages.ByPublishDate.Reverse "Section" "posts") }}

On the local server, this displays the 3 posts then the folder.

{{ range (where .Pages.ByPublishDate.Reverse "Section" "posts") }}
But this displays only the folder.

EDIT : BaseURL is set as the URL of the Netlify website, but seems to be replaced by localhost:1313 automatically when on the local server

Hi,

Do you have the same version of Hugo set on netlify?

Hello, I tried to find this information but I failed…
Is it possible to encounter such a big difference with such a basic code ?!

Yes, if you’re using an earlier version on Netlify. The behaviour of .Pages has changed in version 0.58.

DAMNIT ! Five hours of reading so much pages from the doc, and thanks to you I finally got the answer !! What would you do to fix that ? Should I get an older version of hugo ?
Is there any way to use .Pages to improve the compatibility between the two versions ?

Just make sure you’re using the same version of Hugo for development and deploy.

Waw… That was finally so simple.
Thank you very much, I am so happy to see it’s FIXED !!!
Thanks again, for your quick answer and for helping me…

Cheers !!

What do you want to be displayed on your homepage?

I think what you really want is

{{ range (where .Site.RegularPages.ByPublishDate.Reverse "Section" "posts") }}

(Though the difference between .Site.RegularPages and .Site.Pages is probably negligible because of how you’re filtering through the where clause.)

Yep, that’s it !
I have one more bonus question : I would like to build the navigation menu, where I parse the folders, and for each folders I display the files inside. I tried something but I don’t know what to write (where I put the ???).
Any clue ?

<h1>Navigation</h1>
<ul>
{{range .Pages}}
 <li><h2>{{.Title}}</h2></li>
    <ul>
    {{range where .Site.RegularPages "Section" "????" }}
        <li>{{.Title}}</li>
    {{end}}
    </ul>
{{end}}
</ul>
    </nav>

Thanks !

EDIT : Finally found my answer :
{{range (where .Site.RegularPages "Section" .Path) }}

My journey continues ! Cheers everybody !
(sorry I don’t know how to close the code block)

I think what you might mean is

{{range (where .Site.Pages "Section" .Path) }}

or

{{range .Site.Sections }}

or

{{range $.Sections }}

I think .Site.RegularPages shouldn’t return any Sections.

(And you open and close code blocks in Markdown with three forward ticks```)