Skip to content

Commit

Permalink
Hide empty categries/tags in search (#273)
Browse files Browse the repository at this point in the history
  • Loading branch information
cotes2020 committed Feb 4, 2021
1 parent c8ff81e commit f864b5c
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions _includes/search-loader.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<!--
Jekyll Simple Search loader
See: <https://github.com/christian-fei/Simple-Jekyll-Search>
-->

{% capture result_elem %}
<div class="pl-1 pr-1 pl-sm-2 pr-sm-2 pl-lg-4 pr-lg-4 pl-xl-0 pr-xl-0">
<a href="{{ site.url }}{url}">{title}</a>
<div class="post-meta d-flex flex-column flex-sm-row text-muted mt-1 mb-1">
<div class="mr-sm-4"><i class="far fa-folder fa-fw"></i>{categories}</div>
<div><i class="fa fa-tag fa-fw"></i>{tags}</div>
{categories}
{tags}
</div>
<p>{snippet}</p>
</div>
Expand All @@ -23,6 +24,23 @@
resultsContainer: document.getElementById('search-results'),
json: '{{ '/assets/js/data/search.json' | relative_url }}',
searchResultTemplate: '{{ result_elem | strip_newlines }}',
noResultsText: '{{ not_found }}'
noResultsText: '{{ not_found }}',
templateMiddleware: function(prop, value, template) {
if (prop === 'categories') {
if (value === '') {
return `${value}`;
} else {
return `<div class="mr-sm-4"><i class="far fa-folder fa-fw"></i>${value}</div>`;
}
}

if (prop === 'tags') {
if (value === '') {
return `${value}`;
} else {
return `<div><i class="fa fa-tag fa-fw"></i>${value}</div>`;
}
}
}
});
</script>

0 comments on commit f864b5c

Please sign in to comment.