search.html 1.7 KB

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