Question about content folder structure

I’m in the process of trying to replicate a website that I previously created using cockpit and PHP. One of the key points is that almost every page has at least 2 images. However, I’ve tried a few different ways to structure the content folder, and this has resulted in various issues.

Ultimately, it would be great if someone could just drop an answer with the recommended structure for multiple pages (no listing pages) and their corresponding resources. This way I can compare what I’ve got and see if I’ve made a mistake. For more details, feel free to continue reading.

Note
I currently have a functioning template that should load all pages into a menu in the header and display the text and footer of each page. This works perfectly for the main index.md file (save that the menu isn’t always populated), and changing the structure of the content folders results in the page loading correctly (minus resources and occasionally the menu).

Front Matter
The pages that have image resources use the following format of front matter (with params being left out when there is no description):

resources:
    - name: figure-:counter
      src: "images/figure-1.JPG"
      params:
        - description: "Figcaption"

Structure 1
Originally, I placed all *.md* files into the content folder. So it looked something like this:

index.md
index.de.md
bio.md
bio.de.md
images/

The images folder contains the resources to be used on both the index and the bio page. This works fine for the main index page, but the bio page did not appear in the menu nor would it load when the URL was supplied manually.

Structure 2
Here, I placed each “page” into a separate folder with resources, so it looked like this:

index.md
index.de.md
images/
bio/index.md
bio/index.de.md
bio/images

This method does (mostly) appear in the menu, but trying to use the defined resources fails.

Bonus Question
The design calls for the title/logo of the website to be loaded in the middle of the menu. In PHP I did this by calculating the halfway mark of all the pages in the menu, and then inserting it when the index was correct. Is this possible to do in Hugo/Go? If so, how would one go about getting the total number of pages?

Thanks!

1 Like

I think you need to read and understand this page:

So, if I understand that page correctly, I’m essentially turning my content folder into a leaf bundle by defining the main page as index.md? Which then means I can’t place the other folders in other leaf bundles. And if I define the homepage as a list entry (_index.md) then the .Page.Resources in my template fails?

It also seems to be indicating that Hugo attempts to load some pages as list items - as occasionally an empty page will be loaded with a pluralized title.

1 Like

So, the “_index.md” bundles can have images etc. as resources (and not other pages), but only on the same folder level. So if you treat the home page a litle bit special:

_index.md
_index.de.md
logo.png
bio/index.md
bio/index.de.md
bio/images

It will work. @kaushalmodi is the bundle expert, and can chime in if I got it totally wrong … (I implemented it).

1 Like

I wouldn’t call myself a bundle expert; I did not know that was behavior until today :slight_smile:

I confirm that branch bundles need to have the resources in flat hierarchy, in the same dir as the _index.md.

1 Like

Ahhhh! That definitely brings me closer. My menu is now working as expected. And the templates are loading the correct images in all cases. However, the images are in the wrong order - is it possible to sort the resources by name (which is why I’m using the counter)? I looked at the Page Resources section of the documentation, but I didn’t see any information on this.

Thanks for your prompt responses!

The resources are sorted alphabetically by default; you don’t have to set the name parameter or use the :counter. Try naming the files: 01-figure.jpg, 02-figure.jpg, etc.

That’s a fair point, but I’d prefer it if I could set the order in the front matter, instead of renaming the files (if possible). Because then I can control the expected output in one file, instead of editing multiple ones.

1 Like

The doc is updated with this info and some more… new stuff added to leaf vs branch bundle table.

4 Likes