You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
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 causes JSON.parse() to throw a syntax error in the browser and completely breaks the search capability.
How to Reproduce
Configure any documentation page with ignoreSearch = true in frontmatter.
Build the Hugo site: hugo.
Open the output file public/index.json and validate it using a JSON validator (like JSON.parse() in Node.js).
Observe the parsing failure due to syntax error.
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]
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]