/ _includes / search.html
search.html
 1  {% if site.post_search %}
 2  
 3  <div id="beautifuljekyll-search-overlay">
 4  
 5    <div id="nav-search-exit" title="Exit search">✕</div>
 6    <input type="text" id="nav-search-input" placeholder="Search">
 7    <ul id="search-results-container"></ul>
 8    
 9    <script src="https://unpkg.com/simple-jekyll-search@latest/dest/simple-jekyll-search.min.js"></script>
10    <script>
11      var searchjson = '[ \
12        {% for post in site.posts %} \
13          { \
14            "title"    : "{% if post.title != "" %}{{ post.title | strip_html | escape }}{% else %}{{ post.excerpt | strip_html | escape | strip }}{%endif%}", \
15            "category" : "{{ post.tags | join: \', \' }}", \
16            "url"      : "{{ site.baseurl }}{{ post.url }}", \
17            "date"     : "{{ post.date | date: "%B %e, %Y" | default: "January 1, 1970" }}" \
18          }, \
19        {% endfor %} \
20        {% for page in site.html_pages %}{% if page.title != "{title}" and page.title != "404 - Page not found" %} \
21          { \
22            "title"    : "{% if page.title != "" %}{{ page.title | strip_html | escape }}{% else %}{{ page.excerpt | strip_html | escape | strip }}{% endif %}", \
23            "category" : "{% if page.tags %}{{ page.tags | join: \', \' }}{% else %}page{% endif %}", \
24            "url"      : "{{ site.baseurl }}{{ page.url }}", \
25            "date"     : "{{ page.date | date: '%B %e, %Y' | default: "January 1, 1970" }}" \
26          }{% unless forloop.last %},{% endunless %} \
27        {% endif %}{% endfor %} \
28      ]';
29      searchjson = JSON.parse(searchjson);
30  
31      var sjs = SimpleJekyllSearch({
32        searchInput: document.getElementById('nav-search-input'),
33        resultsContainer: document.getElementById('search-results-container'),
34        json: searchjson
35      });
36    </script>
37  </div>
38  
39  {% endif %}