Skip to content
This repository has been archived by the owner on Mar 16, 2022. It is now read-only.

SimpleJekyllSearch --- failed to get JSON (/search.json) #174

Closed
Funeoz opened this issue Jul 20, 2021 · 10 comments
Closed

SimpleJekyllSearch --- failed to get JSON (/search.json) #174

Funeoz opened this issue Jul 20, 2021 · 10 comments

Comments

@Funeoz
Copy link

Funeoz commented Jul 20, 2021

I tried to use your script but I get this error with both minified and not minified script. I also tried to validate the json : it's valid. I can see the JSON file in the requests tab in the browser.

My search.html file :

---
layout: page
title: Search
---

<script src="https://unpkg.com/simple-jekyll-search@latest/dest/simple-jekyll-search.min.js"></script>
<script>
    SimpleJekyllSearch({
        searchInput: document.getElementById('searchInput'),
        resultsContainer: document.getElementById('resultsContainer'),
        json: '/search.json',
        searchResultTemplate: '<li><a href="{url}" title="{desc}">{title}</a></li>',
        noResultsText: 'No results found',
        fuzzy: false,
    })
</script>

<div class="field has-addons">
    <div class="control is-expanded">
        <input id="searchInput" class="input is-primary" type="text" placeholder="Find an article">
    </div>
</div>

<div id="resultsContainer">

</div>

My search.json file (in root directory) :

---
---
[
  {% for post in site.posts %}
  {
    "title"    : "{{ post.title | strip_html | escape }}",
    "url"      : "{{ site.baseurl }}{{ post.url }}",
    "category" : "{{ post.categories | join: ', '}}",
    "tags"     : "{{ post.tags | join: ', ' }}",
    "date"     : "{{ post.date }}",
    "description" : "{{ post.description | strip_html | strip_newlines | escape }}"
  } {% unless forloop.last %},{% endunless %}
  {% endfor %}
]
@kamil-adam
Copy link

You should start with

---
layout: null
---

@Funeoz
Copy link
Author

Funeoz commented Jul 21, 2021

It still doesn't work.

@Mabbs
Copy link

Mabbs commented Jul 22, 2021

You can verify the generated JSON file first

@Funeoz
Copy link
Author

Funeoz commented Jul 22, 2021

The JSON file is also correct. I've verified it with https://jsonlint.com.

@Erven2016
Copy link

The JSON file is also correct. I've verified it with https://jsonlint.com.

I met this same problem, my json file also verified and is valid.

generated json file:

[
    {
      "title"    : "Welcome to Jekyll!",
      "category" : "jekyllupdate",
      "url"      : "/jekyll/update/2021/07/23/welcome-to-jekyll.html",
      "date"     : "2021-07-23 22:07:02 +0800"
    } 
  
]

@Mabbs
Copy link

Mabbs commented Jul 26, 2021

The JSON file is also correct. I've verified it with https://jsonlint.com.

I met this same problem, my json file also verified and is valid.

generated json file:

[
    {
      "title"    : "Welcome to Jekyll!",
      "category" : "jekyllupdate",
      "url"      : "/jekyll/update/2021/07/23/welcome-to-jekyll.html",
      "date"     : "2021-07-23 22:07:02 +0800"
    } 
  
]

This program doesn't seem to run in IE. what's your browser?

@Erven2016
Copy link

The JSON file is also correct. I've verified it with https://jsonlint.com.

I met this same problem, my json file also verified and is valid.
generated json file:

[
    {
      "title"    : "Welcome to Jekyll!",
      "category" : "jekyllupdate",
      "url"      : "/jekyll/update/2021/07/23/welcome-to-jekyll.html",
      "date"     : "2021-07-23 22:07:02 +0800"
    } 
  
]

This program doesn't seem to run in IE. what's your browser?

The latest version of Google Chrome.

@Funeoz
Copy link
Author

Funeoz commented Jul 26, 2021

I use Firefox. I got the same problem on Brave too.

@Mabbs
Copy link

Mabbs commented Jul 26, 2021

There may be a problem with the Ajax design of this program. I can import JSON manually and use it normally.
My code: https://github.com/Mabbs/mabbs.github.io/blob/master/search.html

@milosmns
Copy link

milosmns commented Mar 4, 2022

Wait why was this closed? There's no official fix for it 🤔

I'm seeing the same issue, Mar 2022.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants