From f864b5c324cfdd6e98f511ce2faca6e237e5b011 Mon Sep 17 00:00:00 2001
From: Cotes Chung <11371340+cotes2020@users.noreply.github.com>
Date: Thu, 4 Feb 2021 23:08:09 +0800
Subject: [PATCH] Hide empty categries/tags in search (#273)
---
_includes/search-loader.html | 24 +++++++++++++++++++++---
1 file changed, 21 insertions(+), 3 deletions(-)
diff --git a/_includes/search-loader.html b/_includes/search-loader.html
index 4a18e6d..2f3ab4d 100644
--- a/_includes/search-loader.html
+++ b/_includes/search-loader.html
@@ -1,13 +1,14 @@
{% capture result_elem %}
{title}
-
{categories}
-
{tags}
+ {categories}
+ {tags}
{snippet}
@@ -23,6 +24,23 @@ SimpleJekyllSearch({
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 `${value}
`;
+ }
+ }
+
+ if (prop === 'tags') {
+ if (value === '') {
+ return `${value}`;
+ } else {
+ return `${value}
`;
+ }
+ }
+ }
});