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/" }}
  {{ 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/

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/ to ./content/images/uploads/, and change each reference in the partial from {{ with site.GetPage "images/uploads/" }} to {{ with site.GetPage "images/uploads/" }} 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/ is a leaf bundle, which means all page-type content below it (such as content/images/uploads/ are considered page resources.

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

Which means you cannot have images/ 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.


@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.