Understanding resource paths in nested subsections

I have an “organically grown” content structure like the following:

section1.md
section1/section2/_index.md
section1/section2/section3/index.md
section1/section2/section3/image.png

Trying to show the image under section3 I would expect the following to work:

![image](image.png)

It does not (tested in various Hugo versions from current down to v0.130.0). What works is this:

![image][section2/section3/image.png]

I have two questions related to understanding the way resource paths work in future uses:

  • why doesn’t the leaf bundle inside the section3 know the image without a path?
  • why does it work using section2/section3 as path, without section1 involved?

Sidenote: I can’t just move section1.md inside the section1 folder as for instance _index.md because that influences how section1/section2/_index.md is built. Also, it’s not a “proper” list page and uses a layout template. Somehow, the _index.md stops working when moving section1.md in. It’s a card house. However, the way they are currently located, they use the layout files they are supposed to use.

Yeah.

content/
├── section1/
│   └── section2/
│       ├── section3/
│       │   ├── image.png
│       │   └── index.md
│       └── _index.md
├── _index.md
└── section1.md    <-- not a great idea

In the above, the only section page (kind is section) is content/section1/section2.

The presence of content/section1.md makes “section1” a page not a section. I’m not even sure that’s determinate from one build to the next, though the --printPathWarnings flag does not indicate a collision.

content/section1/section2/section3/index.md

+++
title = 'Section3'
date = 2025-01-28T08:40:49-08:00
+++

![image](image.png)

The above works fine for me. Try it:

git clone --single-branch -b hugo-forum-topic-53303 https://github.com/jmooring/hugo-testing hugo-forum-topic-53303
cd hugo-forum-topic-53303
hugo server
1 Like