From f01afa96864b1cad2b79be0e893b491ca8bc11d2 Mon Sep 17 00:00:00 2001 From: Peter Noble Date: Tue, 23 Jun 2020 16:21:10 +0100 Subject: [PATCH] Normalise accented characters in website search (#3180) * Normalise accented characters in website search * Move icon name normalisation to Liquid --- index.html | 26 ++++++++++++-------------- site_script.js | 14 ++++++++++++++ 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/index.html b/index.html index 13d492e25..d75a67475 100644 --- a/index.html +++ b/index.html @@ -29,10 +29,6 @@ {% endif %} {% assign filename = filename | downcase %} - {% assign filename = filename | replace: "+", "plus" %} - {% assign filename = filename | replace: ".", "-dot-" %} - {% assign filename = filename | replace: "&", "-and-" %} - {% assign filename = filename | replace: " ", "" | replace: "!", "" | replace: ":", "" | replace: "’", "" | replace: "'", "" %} {% assign filename = filename | replace: "à", "a" | replace: "á", "a" | replace: "â", "a" | replace: "ã", "a" | replace: "ä", "a" %} {% assign filename = filename | replace: "ç", "c" | replace: "č", "c" | replace: "ć", "c" %} {% assign filename = filename | replace: "è", "e" | replace: "é", "e" | replace: "ê", "e" | replace: "ë", "e" %} @@ -44,6 +40,12 @@ {% assign filename = filename | replace: "ý", "y" | replace: "ÿ", "y" %} {% assign filename = filename | replace: "ž", "z" | replace: "ź", "z" %} + {% assign searchTerm = filename %} + {% assign filename = filename | replace: "+", "plus" %} + {% assign filename = filename | replace: ".", "-dot-" %} + {% assign filename = filename | replace: "&", "-and-" %} + {% assign filename = filename | replace: " ", "" | replace: "!", "" | replace: ":", "" | replace: "’", "" | replace: "'", "" %} + {% assign hex = icon.hex %} {% assign hex = icon.hex %} {% assign hexCharacter1 = hex | slice: 0, 1 %} @@ -136,10 +138,10 @@ {% if hslSaturation < 10 %} {% assign hslLuminance = hslLuminance | round: 0 | prepend: "000" | slice: -3, 3 %} - {% capture greyscaleIconsUnsortedString %}{{ greyscaleIconsUnsortedString }}{{ hslLuminance }},{{ filename }},{{ hslHue }},{{ hslSaturation }},{{ hex }},{{ title }},{{ class }},{{ forloop.index }}{% unless forloop.last %};{% endunless %}{% endcapture %} + {% capture greyscaleIconsUnsortedString %}{{ greyscaleIconsUnsortedString }}{{ hslLuminance }},{{ filename }},{{ hslHue }},{{ hslSaturation }},{{ hex }},{{ title }},{{ class }},{{ searchTerm }},{{ forloop.index }}{% unless forloop.last %};{% endunless %}{% endcapture %} {% else %} {% assign hslHue = hslHue | round: 0 | prepend: "000" | slice: -3, 3 %} - {% capture iconsUnsortedString %}{{ iconsUnsortedString }}{{ hslHue }},{{ hslSaturation }},{{ hslLuminance }},{{ filename }},{{ hex }},{{ title }},{{ class }},{{ forloop.index }}{% unless forloop.last %};{% endunless %}{% endcapture %} + {% capture iconsUnsortedString %}{{ iconsUnsortedString }}{{ hslHue }},{{ hslSaturation }},{{ hslLuminance }},{{ filename }},{{ hex }},{{ title }},{{ class }},{{ searchTerm }},{{ forloop.index }}{% unless forloop.last %};{% endunless %}{% endcapture %} {% endif %} {% endfor %} @@ -149,11 +151,11 @@ {% assign allIconNames = "" %} {% for icon in iconsArray %} {% assign iconArray = icon | split: "," %} - {% capture allIconNames %}{{ allIconNames }}"{{ iconArray[5] }}",{% endcapture %} + {% capture allIconNames %}{{ allIconNames }}"{{ iconArray[7] }}",{% endcapture %} {% endfor %} {% for icon in greyscaleIconsArray %} {% assign iconArray = icon | split: "," %} - {% capture allIconNames %}{{ allIconNames }}"{{ iconArray[5] }}"{% unless forloop.last %},{% endunless %}{% endcapture %} + {% capture allIconNames %}{{ allIconNames }}"{{ iconArray[7] }}"{% unless forloop.last %},{% endunless %}{% endcapture %} {% endfor %} @@ -191,12 +193,8 @@ ga('create', 'UA-100751516-2', 'auto'); ga('send', 'pageview'); - - diff --git a/site_script.js b/site_script.js index 98aaff231..757d1f00e 100644 --- a/site_script.js +++ b/site_script.js @@ -65,6 +65,20 @@ return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' ')); } + function normalizeSearchTerm(value) { + return value.toLowerCase().toLowerCase() + .replace(/à|á|â|ã|ä/g, "a") + .replace(/ç|č|ć/g, "c") + .replace(/è|é|ê|ë/g, "e") + .replace(/ì|í|î|ï/g, "i") + .replace(/ñ|ň|ń/g, "n") + .replace(/ò|ó|ô|õ|ö/g, "o") + .replace(/š|ś/g, "s") + .replace(/ù|ú|û|ü/g, "u") + .replace(/ý|ÿ/g, "y") + .replace(/ž|ź/g, "z"); + } + function search(value) { var query = normalizeSearchTerm(value) queryLetters = query.split('');