Git commit and restart local server breaks site.GetPage for headless bundle

I’m running into something I can’t explain and it’s a real hitch in the local dev process so hopefully someone understands why this is happening. I’m using Hugo Static Site Generator v0.61.0/extended darwin/amd64. I will be deploying to Netlify so I’m using a directory of images inside my ./content directory so Netlify CMS can add image content there. I have a special image processing partial to process these images. Like so:

{{ with site.GetPage "images/uploads/_index.md" }}
  {{ with .Resources.GetMatch $img }}
    {{ $processed := .Resize $options }}
    {{ if $doResponsive }}
       {{ $processed2x := .Resize $options2x }}
       <img src="{{ $processed2x.RelPermalink }}" width="{{ $processed.Width }}" height="{{ 
        $processed.Height}}" alt="{{ $alt }}" srcset="{{ $processed.RelPermalink }}, {{ 
        $processed2x.RelPermalink }} 2x">
   {{ else }}
    <img src="{{ $processed.RelPermalink }}" width="{{ $processed.Width }}" height="{{ 
     $processed.Height}}" alt="{{ $alt }}">
  {{ end }}
 {{ end }}
{{ end }}

The reference is to a headless bundle at ./content/images/uploads/_index.md.

This works fine with hugo server -w, but any time that I git commit and restart the server, no images render. If I then go into the content file and change ./content/images/uploads/_index.md to ./content/images/uploads/index.md, and change each reference in the partial from {{ with site.GetPage "images/uploads/_index.md" }} to {{ with site.GetPage "images/uploads/index.md" }} it works again. Until I git commit and restart the server again. Then it is broken again. No images render. Execution doesn’t make it past site.GetPage. I add the underscores back, it works. Until I git commit and restart server. I’ve used this technique in two other projects and have never seen this before. I have no idea what’s going to happen upon deploy. Is there any way to avoid this?

Your best bet for figuring it out is to share a repo that reproduces the issue. Then we’ll figure out how to avoid it. :slight_smile:

Thanks @maiki, I’ve got it:

Branch switch-to-hugo only. Other branches are based off of victor-hugo. This one switches to straight hugo.

Your content/images/index.md is a leaf bundle, which means all page-type content below it (such as content/images/uploads/_index.md) are considered page resources.

If you want to be able to {{ site.GetPage "images/uploads/_index.md" }} you need to have images/_index.md, ie a branch bundle.

Which means you cannot have images/_index.md as a headless bundle, because only leaf bundles can be headless bundles.

I don’t know how this does not break your other projects if you use a similar approach there.

Docs: https://gohugo.io/content-management/page-bundles/

@pointyfar Thanks. Difference from prior projects was the nesting. For some reason it will “kinda work” the way I had it, until the server is restarted.