microcks / microcks/microcks.io
Syntax Corruption and Crash in `index.json` Search Template
- Dominant language
- JavaScript
- Stars
- 25
- Forks
- 88
- Avg merge
- 4h 22m
- Merged PRs (30d)
- 14
Description
### 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.
* **File Link:** [themes/microcks/layouts/_default/index.json](file:///c:/Users/Hp/microcks.io/themes/microcks/layouts/_default/index.json)
* **Code Snippet:**
```json
}{{- 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 causes `JSON.parse()` to throw a syntax error in the browser and completely breaks the search capability.
### How to Reproduce
1. Configure any documentation page with `ignoreSearch = true` in frontmatter.
2. Build the Hugo site: `hugo`.
3. Open the output file `public/index.json` and validate it using a JSON validator (like `JSON.parse()` in Node.js).
4. Observe the parsing failure due to syntax error.
### Reproduction Flow
```mermaid
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]
```
---
Contributor guide
Research direction
Start with themes/microcks/layouts/_default/index.json and inspect the page-range loop that emits commas. Build the site with hugo, then validate public/index.json using JSON.parse() or a JSON validator with a page marked ignoreSearch: true. Done means the generated index remains valid JSON with no trailing or consecutive commas when pages are excluded.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- search
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 76/100