resources/page: Add JSON omitzero tag to PageMatcher.Sites#14875
resources/page: Add JSON omitzero tag to PageMatcher.Sites#14875algojogacor wants to merge 1 commit into
Conversation
Running 'hugo config' with legacy [permalinks] config prints empty
sites sub-maps because Sites has no JSON struct tag. When the field is
zero-valued, json.Marshal emits {matrix:{},complements:{}} which
survives the zero-value cleanup pass.
Adding ensures the field is omitted when its
IsZero() method returns true, matching how the same type is tagged
in commands/config.go.
Fixes #14855
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. |
|
Thanks; I think I prefer #14861 -- as that one works for all maps recursively and it also respects |
Summary
Fixes #14855
Running
hugo configwith legacy[permalinks]configuration prints empty sites sub-maps becausePageMatcher.Siteshas no JSON struct tag.Root Cause
In
resources/page/page_matcher.go:54, theSites sitesmatrix.Sitesfield has no JSON struct tag. When the field is zero-valued during config output,json.Marshalemits{"matrix":{},"complements":{}}, and the downstream zero-value cleanup pass never callsIsZero()or removes these empty sub-maps.Fix
Add
json:"sites,omitzero"to line 54. Go 1.24+omitzerocalls theIsZero()method during marshal, dropping the field entirely when empty. This matches how the samesitesmatrix.Sitestype is already tagged incommands/config.go.Changes
resources/page/page_matcher.go: 1 line changed (+1 -1)Testing
hugo configwith legacy[permalinks]config: No empty sites sub-maps in output ✅hugo configwithout permalinks: No regression ✅