Skip to content

Commit

Permalink
Add search functionality.
Browse files Browse the repository at this point in the history
  • Loading branch information
XhmikosR committed May 13, 2020
1 parent 53a995a commit f2d0db7
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 0 deletions.
6 changes: 6 additions & 0 deletions _includes/js/simple-jekyll-search.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions _includes/search-js.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<script>
(function() {
{% include js/simple-jekyll-search.min.js %}

var searchInput = document.querySelector('.search-input');
var searchResults = document.querySelector('.search-results');

if (searchInput && searchResults) {
window.SimpleJekyllSearch({
json: '/search.json',
noResultsText: '<li class="no-results">Sorry, there are no results for that search.</li>',
resultsContainer: searchResults,
searchInput: searchInput,
searchResultTemplate: '<li><a href="{url}">{title}</a></li>'
});
}
})();
</script>
4 changes: 4 additions & 0 deletions _includes/search.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div class="search-container">
<input class="search-input" type="text" placeholder="Search..." autocomplete="off">
<ul class="search-results"></ul>
</div>
2 changes: 2 additions & 0 deletions _includes/subnav.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
{% include search.html %}

<nav class="bd-subnavbar pt-2 pb-3 pb-md-2">
<div class="container d-flex align-items-md-center py-2">
<nav class="nav mx-auto">
Expand Down
1 change: 1 addition & 0 deletions _layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
</div>

{% include footer.html %}
{% include search-js.html %}

{% include lazyload.html %}
{% include carbonads.html %}
Expand Down
16 changes: 16 additions & 0 deletions search.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
---
---

[
{%- assign sorted_pages = site.posts | sort: 'date' | reverse -%}
{%- for page in sorted_pages -%}

{%- assign content = page.content | split: '<h1 class="post-title"' -%}

{
"content": {{ content[0] | split: '</h1>' | last | strip_html | normalize_whitespace | jsonify }},
"title": {{ page.title | strip_html | normalize_whitespace | jsonify }},
"url": {{ page.url | jsonify }}
}{% unless forloop.last %}, {% endunless %}
{%- endfor -%}
]

0 comments on commit f2d0db7

Please sign in to comment.