Skip to content

Commit 2c56f82

Browse files
committed
Add search functionality.
1 parent 3e9f24d commit 2c56f82

File tree

6 files changed

+47
-0
lines changed

6 files changed

+47
-0
lines changed

src/_includes/js/simple-jekyll-search.min.js

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/_includes/search-js.html

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<script>
2+
(function() {
3+
{% include js/simple-jekyll-search.min.js %}
4+
5+
var searchInput = document.querySelector('.search-input');
6+
var searchResults = document.querySelector('.search-results');
7+
8+
if (searchInput && searchResults) {
9+
window.SimpleJekyllSearch({
10+
json: '/search.json',
11+
noResultsText: '<li class="no-results">Sorry, there are no results for that search.</li>',
12+
resultsContainer: searchResults,
13+
searchInput: searchInput,
14+
searchResultTemplate: '<li><a href="{url}">{title}</a></li>'
15+
});
16+
}
17+
})();
18+
</script>

src/_includes/search.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<div class="search-container">
2+
<input class="search-input" type="text" placeholder="Search..." autocomplete="off">
3+
<ul class="search-results"></ul>
4+
</div>

src/_includes/subnav.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
{% include search.html %}
2+
13
<nav class="bd-subnavbar pt-2 pb-3 pb-md-2">
24
<div class="container d-flex align-items-md-center py-2">
35
<nav class="nav mx-auto">

src/_layouts/default.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
</div>
3535

3636
{% include footer.html %}
37+
{% include search-js.html %}
3738

3839
{% include lazyload.html %}
3940
{% include carbonads.html %}

src/search.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
---
3+
4+
[
5+
{%- assign sorted_pages = site.posts | sort: 'date' | reverse -%}
6+
{%- for page in sorted_pages -%}
7+
8+
{%- assign content = page.content | split: '<h1 class="post-title"' -%}
9+
10+
{
11+
"content": {{ content[0] | split: '</h1>' | last | strip_html | normalize_whitespace | jsonify }},
12+
"title": {{ page.title | strip_html | normalize_whitespace | jsonify }},
13+
"url": {{ page.url | jsonify }}
14+
}{% unless forloop.last %}, {% endunless %}
15+
{%- endfor -%}
16+
]

0 commit comments

Comments
 (0)