Skip to content

Commit 1bc1f37

Browse files
fix(search): unlimited search results (almost)
1 parent d10c12f commit 1bc1f37

File tree

6 files changed

+101
-0
lines changed

6 files changed

+101
-0
lines changed

_includes/post-sharing.html

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!--
2+
Post sharing snippet
3+
-->
4+
5+
<div class="share-wrapper">
6+
<span class="share-label text-muted mr-1">{{ site.data.locales[lang].post.share }}</span>
7+
<span class="share-icons">
8+
{% capture title %}{{ page.title }} - {{ site.title }}{% endcapture %}
9+
{% assign url = page.url | absolute_url %}
10+
11+
{% for share in site.data.share.platforms %}
12+
{% assign link = share.link | replace: 'TITLE', title | replace: 'URL', url %}
13+
<a href="{{ link }}" data-toggle="tooltip" data-placement="top"
14+
title="{{ share.type }}" target="_blank" rel="noopener" aria-label="{{ share.type }}">
15+
<i class="fa-fw {{ share.icon }}"></i>
16+
</a>
17+
{% endfor %}
18+
19+
<i id="copy-link" class="fa-fw fas fa-link small"
20+
data-toggle="tooltip" data-placement="top"
21+
title="{{ site.data.locales[lang].post.button.share_link.title }}"
22+
title-succeed="{{ site.data.locales[lang].post.button.share_link.succeed }}">
23+
</i>
24+
25+
</span>
26+
</div>

_includes/search-loader.html

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<!--
2+
Jekyll Simple Search loader
3+
See: <https://github.com/christian-fei/Simple-Jekyll-Search>
4+
-->
5+
6+
{% capture result_elem %}
7+
<div class="pl-1 pr-1 pl-sm-2 pr-sm-2 pl-lg-4 pr-lg-4 pl-xl-0 pr-xl-0">
8+
<a href="{url}">{title}</a>
9+
<div class="post-meta d-flex flex-column flex-sm-row text-muted mt-1 mb-1">
10+
{categories}
11+
{tags}
12+
</div>
13+
<p>{snippet}</p>
14+
</div>
15+
{% endcapture %}
16+
17+
{% capture not_found %}<p class="mt-5">{{ site.data.locales[lang].search.no_results }}</p>{% endcapture %}
18+
19+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dest/simple-jekyll-search.min.js"></script>
20+
21+
<script>
22+
SimpleJekyllSearch({
23+
searchInput: document.getElementById('search-input'),
24+
resultsContainer: document.getElementById('search-results'),
25+
json: '{{ '/assets/js/data/search.json' | relative_url }}',
26+
searchResultTemplate: '{{ result_elem | strip_newlines }}',
27+
noResultsText: '{{ not_found }}',
28+
limit: 10000,
29+
templateMiddleware: function(prop, value, template) {
30+
if (prop === 'categories') {
31+
if (value === '') {
32+
return `${value}`;
33+
} else {
34+
return `<div class="mr-sm-4"><i class="far fa-folder fa-fw"></i>${value}</div>`;
35+
}
36+
}
37+
38+
if (prop === 'tags') {
39+
if (value === '') {
40+
return `${value}`;
41+
} else {
42+
return `<div><i class="fa fa-tag fa-fw"></i>${value}</div>`;
43+
}
44+
}
45+
}
46+
});
47+
</script>

_includes/search-results.html

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!--
2+
The Search results
3+
-->
4+
<div id="search-result-wrapper" class="d-flex justify-content-center unloaded">
5+
<div class="col-12 col-sm-11 post-content">
6+
<div id="search-hints">
7+
{% include trending-tags.html %}
8+
</div>
9+
<div id="search-results" class="d-flex flex-wrap justify-content-center text-muted mt-3"></div>
10+
</div>
11+
</div>
File renamed without changes.
File renamed without changes.

assets/js/data/search.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
layout: compress
3+
---
4+
5+
[
6+
{% for post in site.posts %}
7+
{
8+
"title": "{{ post.title | escape }}",
9+
"url": "{{ post.url | relative_url }}",
10+
"categories": "{{ post.categories | join: ', '}}",
11+
"tags": "{{ post.tags | join: ', ' }}",
12+
"date": "{{ post.date }}",
13+
{% include no-linenos.html content=post.content %}
14+
"snippet": "{{ content | strip_html | strip_newlines | remove_chars | escape | replace: '\', '\\\\' }}"
15+
}{% unless forloop.last %},{% endunless %}
16+
{% endfor %}
17+
]

0 commit comments

Comments
 (0)