Pages and navigation build inconsistently

#1

Hey All,

Hope you can assist me with this issue. New to Hugo, and for the most part it is working great but, I am experience this strange issue where pages and the menu is built inconsistently. So, the site is very small, ~4 pages and I have the pages set-up as follows:

content
---- pages
------ about.md
------ portfolio.md
------ contact.md
index.md

I then run hugo server -D and point the browser at localhost:1313. Now, sometimes the page content loads from index.md as expected, and the menu items are: home - about - portfolio - contact

Other times however the content from index.md is not, and the menu only has the entry for home

With regards to the menu specifically, I have the following in the frontmatter of all the pages:

linktitle: "home"
menu: "main"

What I also see is that, when the content is not loaded on the landing page(index.md), then trying to manually navigate to for example localhost:1313/pages/about results in a 404.

Not sure what is causing this inconsistency. Any idea, suggestions? I would really appreciate any help.

Also, just FYI. I have also tried running hugo server -D --disableFastRender as well as hugo server -D --disableFastRender --gc

Thanks in advance.

#2

Hi there – we’d need to see your site code in order to help you. Please see requesting help.

Just a guess, but this 404 is likely because you don’t have a single page template defined, e.g. layouts/_default/single.html. We would need to see your code to confirm, though.

#3

Sometimes it does work just fine though. As mentioned, when the landing page at localhost:1313 loads the content from index.md, the menu is also correct, and the pages do load. Below is a screenshot of the theme directory:

#4

Sorry, I’m unable to help you based off that screenshot. I’d need to see your actual code. If you can’t do that for some reason, at least provide a link to the theme you’re using.

#5

Hello @schalkneethling, I ran into the same issue sometimes last week. I was able to solve the inconsistency by renaming content/index.md to content/_index.md.

It worked for me, perhaps it could work for you too.

#6

Thanks Weru, will give it a try.

#7

let me know how it goes

#8

Hey zwbetz, I pushed the code here: https://github.com/MechanicalInk/goldratt_pl - Thanks for your help!

#9

So it solved part of the problem it seems i.e. The pages inside the pages folder now loads, and the navigation items are present. But now, the content from _index.md does not load on the landing page.

I thought perhaps I needed both a _index.md and index.md with the second containing the content, but that does not work either. Perhaps there is another way to define what the landing page should be when one load the root of the site i.e. localhost:1313

#10

That index.md has draft: true in the front matter. Make sure all your pages aren’t set to drafts. :slight_smile:

#11

The problem with the home page could be inside config.toml file, here:

baseURL = "http://goldratt.pl/"

You should probably have it like so

baseURL = ""
#12

In retrospect, I think @maiki is right … the problem isn’t necessarily with the baseURL = "http://goldratt.pl/"

#13

This is incorrect. The baseURL is fine, and should be the production URL, as it is – FYI when running hugo server locally, it makes the baseURL as http://localhost:1313/

#14

@schalkneethling @weru – for when to use index.md (leaf) vs _index.md (branch) please see page bundles

#15

Thanks. My understanding is that hugo server -D will build and “deploy” drafts as well?

#16

Thanks zwebtz. Seems that my use of index.md then is correct. The content is still not showing up as the homepage though :frowning: Is there some config I am missing?

#17

In /goldratt_pl/layouts/index.html I added {{ .Content }} and the page content shows. Without that I am not sure how it would, so maybe you were changing that while developing.

#18

Thanks @maiki - I was just looking at that, and it seemed to me like it was actually set-up to do some form of extracts and pagination. Basically like a blogs landing page. Let me try removing all that and replacing it with {{.Content }}

#19

Nope, no go. Changed index.html to be:

{{ partial "header.html" . }}
	<main>
		{{ .Content }}
	</main>
{{ partial "footer.html" . }}

Content is still not showing up on localhost:1313 unfortunately.

#20

Hi,

So to summarize, you have done all of the following and it still does not work for you?

  • Rename content/index.md to content/_index.md
  • Set content/_index.md front matter draft:false OR run hugo server -D
  • Add {{ .Content }} somewhere in layouts/index.html

I cloned your repo just now and did those exact steps and I can see the menu for the 4 pages and the _index.md content when I run hugo server -D.

1 Like