From 01d52e8730f6710df3a7eaaad9b64cec54d92eb7 Mon Sep 17 00:00:00 2001 From: Michael Schnerring <3743342+schnerring@users.noreply.github.com> Date: Thu, 14 Oct 2021 23:56:35 +0200 Subject: [PATCH 1/9] Plainify flexsearch index values --- assets/js/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/js/index.js b/assets/js/index.js index 26f78b7..7bfa6c5 100644 --- a/assets/js/index.js +++ b/assets/js/index.js @@ -108,7 +108,7 @@ Source: {{ else -}} description: {{ .Summary | plainify | jsonify }}, {{ end -}} - content: {{ .Content | jsonify }} + content: {{ .Plain | jsonify }} }) {{ if ne (add $index 1) $len -}} .add( From 98c69a6a522e3c26c67de7faf3372dc5868f250b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 15 Oct 2021 06:03:45 +0000 Subject: [PATCH 2/9] chore(deps-dev): bump mermaid from 8.13.2 to 8.13.3 Bumps [mermaid](https://github.com/knsv/mermaid) from 8.13.2 to 8.13.3. - [Release notes](https://github.com/knsv/mermaid/releases) - [Changelog](https://github.com/mermaid-js/mermaid/blob/develop/docs/CHANGELOG.md) - [Commits](https://github.com/knsv/mermaid/compare/8.13.2...8.13.3) --- updated-dependencies: - dependency-name: mermaid dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- package-lock.json | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/package-lock.json b/package-lock.json index 716eca0..48187c9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3710,9 +3710,9 @@ } }, "node_modules/dompurify": { - "version": "2.3.1", - "resolved": "https://registry.npmjs.org/dompurify/-/dompurify-2.3.1.tgz", - "integrity": "sha512-xGWt+NHAQS+4tpgbOAI08yxW0Pr256Gu/FNE2frZVTbgrBUn8M7tz7/ktS/LZ2MHeGqz6topj0/xY+y8R5FBFw==", + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/dompurify/-/dompurify-2.3.3.tgz", + "integrity": "sha512-dqnqRkPMAjOZE0FogZ+ceJNM2dZ3V/yNOuFB7+39qpO93hHhfRpHw3heYQC7DPK9FqbQTfBKUJhiSfz4MvXYwg==", "dev": true }, "node_modules/domutils": { @@ -5914,16 +5914,16 @@ } }, "node_modules/mermaid": { - "version": "8.13.2", - "resolved": "https://registry.npmjs.org/mermaid/-/mermaid-8.13.2.tgz", - "integrity": "sha512-qTFI7MfC2d+x0Hft5gx063EH9tZg36lERG8o7Zq0Ag+MnO8CgVaMZEU6oA8gzTtTn9upMdy4UlYSLVmavu27cQ==", + "version": "8.13.3", + "resolved": "https://registry.npmjs.org/mermaid/-/mermaid-8.13.3.tgz", + "integrity": "sha512-w6KmDtSzkk856WUVqlBsyLZX0q4Jr35IlxiHTPTaWwMgWHFpI8rEJzcxWoyrpxeT/Rac/vvvSFOZymDTeA0iiA==", "dev": true, "dependencies": { "@braintree/sanitize-url": "^3.1.0", "d3": "^7.0.0", "dagre": "^0.8.5", "dagre-d3": "^0.6.4", - "dompurify": "2.3.1", + "dompurify": "2.3.3", "graphlib": "^2.1.8", "khroma": "^1.4.1", "moment-mini": "^2.24.0", @@ -11334,9 +11334,9 @@ } }, "dompurify": { - "version": "2.3.1", - "resolved": "https://registry.npmjs.org/dompurify/-/dompurify-2.3.1.tgz", - "integrity": "sha512-xGWt+NHAQS+4tpgbOAI08yxW0Pr256Gu/FNE2frZVTbgrBUn8M7tz7/ktS/LZ2MHeGqz6topj0/xY+y8R5FBFw==", + "version": "2.3.3", + "resolved": "https://registry.npmjs.org/dompurify/-/dompurify-2.3.3.tgz", + "integrity": "sha512-dqnqRkPMAjOZE0FogZ+ceJNM2dZ3V/yNOuFB7+39qpO93hHhfRpHw3heYQC7DPK9FqbQTfBKUJhiSfz4MvXYwg==", "dev": true }, "domutils": { @@ -13009,16 +13009,16 @@ "dev": true }, "mermaid": { - "version": "8.13.2", - "resolved": "https://registry.npmjs.org/mermaid/-/mermaid-8.13.2.tgz", - "integrity": "sha512-qTFI7MfC2d+x0Hft5gx063EH9tZg36lERG8o7Zq0Ag+MnO8CgVaMZEU6oA8gzTtTn9upMdy4UlYSLVmavu27cQ==", + "version": "8.13.3", + "resolved": "https://registry.npmjs.org/mermaid/-/mermaid-8.13.3.tgz", + "integrity": "sha512-w6KmDtSzkk856WUVqlBsyLZX0q4Jr35IlxiHTPTaWwMgWHFpI8rEJzcxWoyrpxeT/Rac/vvvSFOZymDTeA0iiA==", "dev": true, "requires": { "@braintree/sanitize-url": "^3.1.0", "d3": "^7.0.0", "dagre": "^0.8.5", "dagre-d3": "^0.6.4", - "dompurify": "2.3.1", + "dompurify": "2.3.3", "graphlib": "^2.1.8", "khroma": "^1.4.1", "moment-mini": "^2.24.0", From 611f836e02a8597302bb21322c4b37e55378708a Mon Sep 17 00:00:00 2001 From: Michael Schnerring <3743342+schnerring@users.noreply.github.com> Date: Fri, 15 Oct 2021 14:22:46 +0200 Subject: [PATCH 3/9] Simplify heading rendering --- layouts/_default/_markup/.gitkeep | 0 layouts/_default/_markup/render-heading.html | 1 + layouts/docs/single.html | 4 ++-- layouts/partials/main/headline-hash.html | 1 - 4 files changed, 3 insertions(+), 3 deletions(-) delete mode 100644 layouts/_default/_markup/.gitkeep create mode 100644 layouts/_default/_markup/render-heading.html delete mode 100644 layouts/partials/main/headline-hash.html diff --git a/layouts/_default/_markup/.gitkeep b/layouts/_default/_markup/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/layouts/_default/_markup/render-heading.html b/layouts/_default/_markup/render-heading.html new file mode 100644 index 0000000..8abeac6 --- /dev/null +++ b/layouts/_default/_markup/render-heading.html @@ -0,0 +1 @@ +{{ .Text | safeHTML }} diff --git a/layouts/docs/single.html b/layouts/docs/single.html index 5c58c54..28bb90b 100644 --- a/layouts/docs/single.html +++ b/layouts/docs/single.html @@ -31,7 +31,7 @@ {{ partial "sidebar/docs-toc.html" . }} {{ end -}} - {{ partial "main/headline-hash.html" .Content }} + {{ .Content }} {{ if .Site.Params.editPage -}} {{ partial "main/edit-page.html" . }} {{ end -}} @@ -45,4 +45,4 @@ --> -{{ end }} \ No newline at end of file +{{ end }} diff --git a/layouts/partials/main/headline-hash.html b/layouts/partials/main/headline-hash.html deleted file mode 100644 index 826fa32..0000000 --- a/layouts/partials/main/headline-hash.html +++ /dev/null @@ -1 +0,0 @@ -{{ . | replaceRE "()" `${1} ${3}` | safeHTML }} \ No newline at end of file From 7debd0ae6256c89b3c76937d52e802af28562624 Mon Sep 17 00:00:00 2001 From: Michael Schnerring <3743342+schnerring@users.noreply.github.com> Date: Fri, 15 Oct 2021 15:12:42 +0200 Subject: [PATCH 4/9] Refactor show_results (flexsearch) to be more descriptive --- assets/js/index.js | 34 +++++++++++++++++++++------------- 1 file changed, 21 insertions(+), 13 deletions(-) diff --git a/assets/js/index.js b/assets/js/index.js index 7bfa6c5..058a107 100644 --- a/assets/js/index.js +++ b/assets/js/index.js @@ -121,31 +121,39 @@ Source: function show_results(){ const maxResult = 5; + var searchQuery = this.value; + var results = index.search(searchQuery, {limit: maxResult, enrich: true}); - var value = this.value; - var results = index.search(value, {limit: maxResult, enrich: true}); - - suggestions.classList.remove('d-none'); - suggestions.innerHTML = ""; - - //flatSearch now returns results for each index field. create a single list - const flatResults = {}; //keyed by href to dedupe results + // flatten results since index.search() returns results for each indexed field + const flatResults = {}; // keyed by href to dedupe results for (const result of results.flatMap(r => r.result)) { flatResults[result.doc.href] = result.doc; } - //construct a list of suggestions list + suggestions.innerHTML = ""; + suggestions.classList.remove('d-none'); + + // construct a list of suggestions for(const href in flatResults) { const doc = flatResults[href]; const entry = document.createElement('div'); - entry.innerHTML = ''; + suggestions.appendChild(entry); - entry.querySelector('a').href = href; - entry.querySelector('span:first-child').textContent = doc.title; - entry.querySelector('span:nth-child(2)').textContent = doc.description; + const a = document.createElement('a'); + a.href = href; + entry.appendChild(a); + + const title = document.createElement('span'); + title.textContent = doc.title; + a.appendChild(title); + + const description = document.createElement('span'); + description.textContent = doc.description; + a.appendChild(description); suggestions.appendChild(entry); + if(suggestions.childElementCount == maxResult) break; } } From a3a636581738b1110d7c518f7f398f21a5e667f4 Mon Sep 17 00:00:00 2001 From: Michael Schnerring <3743342+schnerring@users.noreply.github.com> Date: Fri, 15 Oct 2021 15:13:18 +0200 Subject: [PATCH 5/9] Remove obsolete query suggestion logic: accept_suggestion (flexsearch) --- assets/js/index.js | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/assets/js/index.js b/assets/js/index.js index 058a107..8290ac4 100644 --- a/assets/js/index.js +++ b/assets/js/index.js @@ -117,7 +117,6 @@ Source: ; search.addEventListener('input', show_results, true); - suggestions.addEventListener('click', accept_suggestion, true); function show_results(){ const maxResult = 5; @@ -157,15 +156,4 @@ Source: if(suggestions.childElementCount == maxResult) break; } } - - function accept_suggestion(){ - - while(suggestions.lastChild){ - - suggestions.removeChild(suggestions.lastChild); - } - - return false; - } - }()); From a409d55365839e4afd9e2d38e0ce826b0f914887 Mon Sep 17 00:00:00 2001 From: Michael Schnerring <3743342+schnerring@users.noreply.github.com> Date: Fri, 15 Oct 2021 15:16:33 +0200 Subject: [PATCH 6/9] Use Map instead of object for flat flexsearch results --- assets/js/index.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/assets/js/index.js b/assets/js/index.js index 8290ac4..61d9aa8 100644 --- a/assets/js/index.js +++ b/assets/js/index.js @@ -124,18 +124,17 @@ Source: var results = index.search(searchQuery, {limit: maxResult, enrich: true}); // flatten results since index.search() returns results for each indexed field - const flatResults = {}; // keyed by href to dedupe results + const flatResults = new Map(); // keyed by href to dedupe results for (const result of results.flatMap(r => r.result)) { - flatResults[result.doc.href] = result.doc; + if (flatResults.has(result.doc.href)) continue; + flatResults.set(result.doc.href, result.doc); } suggestions.innerHTML = ""; suggestions.classList.remove('d-none'); // construct a list of suggestions - for(const href in flatResults) { - const doc = flatResults[href]; - + for(const [href, doc] of flatResults) { const entry = document.createElement('div'); suggestions.appendChild(entry); From 1710b8082932e1e5f27c3c119cf25bcd794f9c2a Mon Sep 17 00:00:00 2001 From: Michael Schnerring <3743342+schnerring@users.noreply.github.com> Date: Fri, 15 Oct 2021 15:34:57 +0200 Subject: [PATCH 7/9] Add descriptive class names for flexsearch result items --- assets/js/index.js | 2 ++ assets/scss/components/_search.scss | 8 ++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/assets/js/index.js b/assets/js/index.js index 61d9aa8..7f4bfcc 100644 --- a/assets/js/index.js +++ b/assets/js/index.js @@ -144,10 +144,12 @@ Source: const title = document.createElement('span'); title.textContent = doc.title; + title.classList.add("suggestion__title"); a.appendChild(title); const description = document.createElement('span'); description.textContent = doc.description; + description.classList.add("suggestion__description"); a.appendChild(description); suggestions.appendChild(entry); diff --git a/assets/scss/components/_search.scss b/assets/scss/components/_search.scss index 6beebf2..7395004 100644 --- a/assets/scss/components/_search.scss +++ b/assets/scss/components/_search.scss @@ -43,12 +43,12 @@ font-size: $font-size-base; } -#suggestions span:first-child { +.suggestion__title { font-weight: $headings-font-weight; color: $black; } -#suggestions span:nth-child(2) { +.suggestion__description { color: $gray-700; } @@ -61,7 +61,7 @@ display: flex; } - #suggestions span:first-child { + .suggestion__title { width: 9rem; padding-right: 1rem; border-right: 1px solid $gray-200; @@ -69,7 +69,7 @@ text-align: right; } - #suggestions span:nth-child(2) { + .suggestion__description { width: 19rem; padding-left: 1rem; } From af6c51f6f2962257c26ec72fd93759bee3562cac Mon Sep 17 00:00:00 2001 From: Michael Schnerring <3743342+schnerring@users.noreply.github.com> Date: Fri, 15 Oct 2021 15:38:04 +0200 Subject: [PATCH 8/9] If flexsearch returns no results, display message --- assets/js/index.js | 9 +++++++++ assets/scss/components/_search.scss | 11 ++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/assets/js/index.js b/assets/js/index.js index 7f4bfcc..24049b9 100644 --- a/assets/js/index.js +++ b/assets/js/index.js @@ -133,6 +133,15 @@ Source: suggestions.innerHTML = ""; suggestions.classList.remove('d-none'); + // inform user that no results were found + if (flatResults.size === 0) { + const noResultsMessage = document.createElement('div') + noResultsMessage.innerHTML = `No results for "${searchQuery}"` + noResultsMessage.classList.add("suggestion__no-results"); + suggestions.appendChild(noResultsMessage); + return; + } + // construct a list of suggestions for(const [href, doc] of flatResults) { const entry = document.createElement('div'); diff --git a/assets/scss/components/_search.scss b/assets/scss/components/_search.scss index 7395004..45ec2af 100644 --- a/assets/scss/components/_search.scss +++ b/assets/scss/components/_search.scss @@ -10,11 +10,15 @@ z-index: $zindex-dropdown; } +#suggestions a, +.suggestion__no-results { + padding: 0.75rem; + margin: 0 0.5rem; +} + #suggestions a { display: block; text-decoration: none; - padding: 0.75rem; - margin: 0 0.5rem; } #suggestions a:focus { @@ -48,7 +52,8 @@ color: $black; } -.suggestion__description { +.suggestion__description, +.suggestion__no-results { color: $gray-700; } From 4d9221d7a41ea910b21d96df500c14360dd5573f Mon Sep 17 00:00:00 2001 From: Michael Schnerring <3743342+schnerring@users.noreply.github.com> Date: Fri, 15 Oct 2021 15:42:26 +0200 Subject: [PATCH 9/9] flexsearch: only display 'no results' message if search query is not empty --- assets/js/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/js/index.js b/assets/js/index.js index 24049b9..b99ab90 100644 --- a/assets/js/index.js +++ b/assets/js/index.js @@ -134,7 +134,7 @@ Source: suggestions.classList.remove('d-none'); // inform user that no results were found - if (flatResults.size === 0) { + if (flatResults.size === 0 && searchQuery) { const noResultsMessage = document.createElement('div') noResultsMessage.innerHTML = `No results for "${searchQuery}"` noResultsMessage.classList.add("suggestion__no-results");