Index layout file manually prints braces, quotes, keys, and values to build index.json, but fails to place commas - #557
Open
aniket866 wants to merge 2 commits into
Open
Conversation
Signed-off-by: aniket866 <iamaniketkumarmaner@gmail.com>
aniket866
marked this pull request as draft
July 31, 2026 19:22
Signed-off-by: aniket866 <iamaniketkumarmaner@gmail.com>
aniket866
marked this pull request as ready for review
July 31, 2026 19:56
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #556
Describe the bug
Description
The search index layout file manually prints braces, quotes, keys, and values to build
index.json, but fails to place commas between items in the page range loop, or prints trailing commas when pages are excluded.}{{- if eq $item $len -}}{{- else -}},{{- end -}}Why It Breaks
Without proper comma delimiters between items in the inner loop, the result is malformed JSON. Furthermore, if a page is excluded (e.g.,
ignoreSearch: true), the hardcoded comma rendering logic results in trailing commas (e.g.[ { ... }, ]) or consecutive commas (e.g.,,,). This causesJSON.parse()to throw a syntax error in the browser and completely breaks the search capability.How to Reproduce
ignoreSearch = truein frontmatter.hugo.public/index.jsonand validate it using a JSON validator (likeJSON.parse()in Node.js).Reproduction Flow
graph TD A[Start: Build Search Index] --> B[Hugo iterates pages in Group] B --> C{Is page ignored?} C -- Yes --> D[Page skipped; index incremented] C -- No --> E[Object printed] D --> F[Prints delimiter comma anyway] F --> G[Generates trailing comma at end of list: ', ]'] G --> H[Client script fetches index.json] H --> I[Execute JSON.parse()] I --> J[Error: SyntaxError: Unexpected token ] in JSON]