From 21826753d7d1c1b96ed4b5dc85faa0570f2541d6 Mon Sep 17 00:00:00 2001
From: TonyFord <tonyford@strategy-investor.de>
Date: Thu, 11 Jun 2020 16:40:46 +0200
Subject: [PATCH] bug fixed search function

---
 assets/js/simple-jekyll-search.js | 9 ++++++++-
 search.json                       | 6 +++---
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/assets/js/simple-jekyll-search.js b/assets/js/simple-jekyll-search.js
index 1bed9ef..e768525 100644
--- a/assets/js/simple-jekyll-search.js
+++ b/assets/js/simple-jekyll-search.js
@@ -264,7 +264,7 @@ function compile (data) {
     searchInput: null,
     resultsContainer: null,
     json: [],
-    searchResultTemplate: '<li><a href="?order={hid}" title="{description}">{hid} <sub>#{tags}</sub> - {headline} - {price} FAIR ( {price-per-unit} {price-reference} ) <sup>{id}</sup></a></li>',
+    searchResultTemplate: '<li><a href="?order={hid}" title="{description}">{hid} <sub>#{tags}</sub> - {headline} - <span data-price="{price} FAIR">{price} FAIR</span> <span data-price="{price-per-unit} {price-reference}">( {price-per-unit} {price-reference} )</span> <sup>{id}</sup></a></li>',
     templateMiddleware: function () {},
     noResultsText: 'No results found',
     limit: 10,
@@ -358,6 +358,13 @@ function compile (data) {
     if (isValidQuery(query)) {
       render(repository.search(query))
     }
+    $.each( $('#results-container > li > a'),
+      function(i,v){
+        var price_fair=$( $(v).children()[1]).attr('data-price');
+        var price_ref=$( $(v).children()[2]).attr('data-price');
+        $( $(v).children()[2]).toggleClass('d-none', price_fair == price_ref );
+      }
+    )
   }
 
   function render (results) {
diff --git a/search.json b/search.json
index 76b2d4d..cc3a6ae 100644
--- a/search.json
+++ b/search.json
@@ -13,12 +13,12 @@ layout: null
       "description" : "{{ o.description }}",
       "tags"        : "{{ o.tags }}",
       "id"     : "@{{ reg_entry.id }}",
-      "hid"    : "{{ reg_entry.id | append: o.headline | sha256 | slice: 0,6 }}",
-      "price-per-unit" : {{ o.price-per-unit }},
+      "hid"    : "{{ reg_entry.id | append: o.headline | append: o.description | sha256 | slice: 0,6 }}",
+      "price-per-unit" : "{{ o.price-per-unit | decimals }}",
       {% capture priceref %}{{ o.price-reference | split: ',' | join: '-' }}{% endcapture %}
       {% capture price_ex %}{% if site.data.price-sources[priceref] %}{{ site.data.price-sources[priceref].price | plus: 0.00001 | round: 4 }}{% else %}1{% endif %}{% endcapture %}
       {% capture price %}{% if price_ex != "" %}{{price_ex}}{% else %}{{ o.price-source }}{% endif %}{% endcapture %}
-      "price-reference" : "{% assign pr = o.price-reference | split: ',' %}{{ pr[1] }}",
+      "price-reference" : "{% assign pr = o.price-reference | split: ',' %}{% if pr[1] %}{{ pr[1] }}{% else %}{{ pr[0] }}{% endif %}",
       "price" : "{{ o.price-per-unit  | divided_by: price | round: 1 | decimals }}"
     }
       {% endfor %}
-- 
GitLab