Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Search functionality is not working out of the box, zzzz-search-data.json is getting rendered as a HTML page instead of a JSON file #1466

Closed
5hwb opened this issue Apr 24, 2024 · 2 comments · Fixed by #1468
Labels
bug status: wip Issues being worked on by someone.

Comments

@5hwb
Copy link

5hwb commented Apr 24, 2024

Describe the bug

When creating a Jekyll site and adding on the just-the-docs theme later on, the search functionality does not work, generating no output. Further investigation revealed that the search data JSON file (assets/js/zzzz-search-data.json) was being treated by the template engine as a HTML page and applying the associated HTML markup and styling to the entire file, causing the JSON to become unparsable and preventing Lunr.js from successfully starting.

Opening up the browser dev tools reveals an error Uncaught SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data.

There is a simple workaround which involves setting the layout to none in the front matter of assets/js/zzzz-search-data.json, preventing the template engine from rendering the JSON as a HTML page. Open assets/js/zzzz-search-data.json and replace the front matter:

---
permalink: /assets/js/search-data.json
---

with the following:

---
layout: none
permalink: /assets/js/search-data.json
---

To Reproduce
Steps to reproduce the behavior:

  1. Follow the Jekyll step-by-step tutorial to setup a Jekyll site
  2. In the site Gemfile, add the line gem "just-the-docs", "~> 0.8.2", the latest version as of 24 Apr 2024, then run bundle install
  3. Enable search as in the just-the-docs docs - set search_enabled = true in the project config at _config.yml
  4. Generate search index - bundle exec just-the-docs rake search:init
  5. Run the site locally - bundle exec jekyll serve
  6. Open the site and type anything in the search bar
  7. No results appear from the search.

Expected behavior
Search results should appear when typing in the search bar.

Screenshots
If applicable, add screenshots to help explain your problem.

Out of the box: Search functionality not working
image

What should happen: Search results show up after typing in search bar

image

Desktop (please complete the following information):

  • OS: macOS Sonoma 14.4.1
  • Browser: Firefox 125.0.2 (64-bit), Chrome 124.0.6367.62 (Official Build) (arm64)
  • Version: 0.8.2

Additional context

Ruby version is 3.3.0 and was installed via the asdf version management tool.

@5hwb 5hwb added the bug label Apr 24, 2024
@mattxwang
Copy link
Member

Hi @5hwb, thank you for submitting an issue! I appreciate your in-depth steps to reproduce this problem - and it makes complete sense (we just fixed a similar issue in #1447). In particular, a concise reproduction pattern is:

  1. clone the template repository
  2. add the following to _config.yml:
defaults:
  - scope:
      path: ""
    values:
      layout: "default"

So, your suggested solution should resolve this problem; I will use layout: null (as explained in #1447). I'll submit a PR shortly. Thanks!

@5hwb
Copy link
Author

5hwb commented Apr 25, 2024

No worries, glad to know it helped!

mattxwang added a commit that referenced this issue May 16, 2024
…yout (#1468)

Fixes #1466. Prior art: #1447. Otherwise self-explanatory.

To test:

1. First, clone [template repository](https://github.com/just-the-docs/just-the-docs-template/tree/main). Observe that search works.
2. Next, add a default layout to all files
```yml
defaults:
  - scope:
      path: ""
    values:
      layout: "default"
```
3. Observe that search no longer works.
4. Apply this patch
5. Observe that search works again!
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug status: wip Issues being worked on by someone.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants