Skip to content

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 4 commits into
microcks:masterfrom
aniket866:fixing-comma-handling
Open

aniket866 wants to merge 4 commits into
microcks:masterfrom
aniket866:fixing-comma-handling

Conversation

@aniket866

@aniket866 aniket866 commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

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.

  • File Link: themes/microcks/layouts/_default/index.json
  • Code Snippet:
    }{{- 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.

Signed-off-by: aniket866 <iamaniketkumarmaner@gmail.com>
@aniket866
aniket866 marked this pull request as draft July 31, 2026 19:22
Signed-off-by: aniket866 <iamaniketkumarmaner@gmail.com>
@aniket866
aniket866 marked this pull request as ready for review July 31, 2026 19:56

@yada yada left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The jsonify approach fixes the fragile delimiter handling, but the final commit introduces a search-index regression. Moving the section-expansion block outside .Pages.GroupBy "Section" and checking $.Section means it never executes for the homepage.

The generated index drops from 174 entries to 9, removing all Author, Blog, and Documentation results. Please keep that block inside the inner page loop, using the current page’s .Section and .Title, then serialize the accumulated entries with jsonify. A test should also parse index.json and verify representative documentation and blog URLs remain indexed.

Last but not least, the PR should be revised into a Hugo-native, test-covered solution before merging:

  1. Use a local newScratch instead of deprecated page-level $.Scratch.
  2. Add a build test that parses public/index.json and checks representative Blog and Documentation URLs.
  3. Either centralize the shared logic in a partial or confirm whether the duplicate documentation template is still needed.

@Vaishnav88sk

Copy link
Copy Markdown
Contributor

I think this needs to be tested and verified locally to avoid previous consequences (c9ed769).

@yada

yada commented Oct 8, 2026

Copy link
Copy Markdown
Member

@aniket866 any news regarding the requested change? Thanks

Signed-off-by: aniket866 <iamaniketkumarmaner@gmail.com>
@aniket866
aniket866 requested a review from yada October 10, 2026 18:00
@aniket866

aniket866 commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor Author

@yada I have done the requested changes , sorry for the delay , let me know any more changes required , I will be doing that actively.

image

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Syntax Corruption and Crash in index.json Search Template

4 participants