Trying to sort and group headless page bundle

I feel like I’m missing something simple here, but after reading the doc page, multiple threads on here, and a couple of (great) blog posts, I’m still missing what I need to do.

The original code that worked:

{{ $notices := .Site.GetPage "/deprecation-notices" }}

{{ with $notices }}
{{ range .Pages.GroupByParam "effective" }}
<h3 class="h4">{{ dateFormat "January 2006" .Key }}</h3>
<ol>
  {{ range .Pages.ByTitle }}
  <li><a href="#{{ anchorize .Title }}">{{ .Title }}</a></li>
  {{ end }}
</ol>
{{ end }}
{{ end }}

(This is in a private repo, sorry I can’t link directly to it). When this was accessed as a page bundle it worked fine, but the problem of course is that Hugo generates html files for all of the snippets I have in /content/deprecation-notices/. So I did some more research and discovered headless bundles! Problem solved! Except once I transition it to a headless bundle, the above code no longer works.

I’ve tried so many combinations it’s not worth putting them all here but needless to say once I use .Resources to get the pages I want from $notices, the .Pages.GroupByParam throws a “can’t evaluate field Pages” error. I’ve tried using group and sort but with no success.

Not sure how to fix the above code once I’ve moved from a page bundle to a headless bundle. Any advice or pointing in the right direction is greatly appreciated.

I’m getting closer, I figured out how to sort within the range statement:

{{ range sort . ".Params.effective" }}

…but what I need to do is group them by that param, then sort them by title.

If I try to group the .GetPage, I get the error “*cannot convert type hugolib.pageState to Pages”. If I try after using .Resources, I get the error “grouping not supported for type resource.Resources” which is starting to make me wonder if I can even do what I want to.

I feel like I need to learn Go to know what the heck is going on half the time. I’m perfectly comfortable with PHP and JavaScript and yet none of that knowledge seems to be helping with Hugo templating.

Anyone willing to spitball some ideas? Something might stick.

Maybe I need to come at this from another direction, leave the deprecation-notices as a page bundle and simply remove them from the sitemap and delete out of public during my build process.

Probably the easiest solution is to migrate everything into a JSON data file. Come back to headless bundles when I don’t need to group them by any parameters.