Browse Source

fix(fuzzy-search): handle search layout hotkey assignments properly

jsonify hotkeys passed from go-html-templates for use in javascript
Josh Habdas 6 months ago
parent
commit
630d3a9339
Signed by: Josh Habdas <jhabdas@protonmail.com> GPG Key ID: B148B31154C75A74
3 changed files with 5 additions and 3 deletions
  1. 1
    1
      archetypes/search.md
  2. 3
    1
      assets/js/search.js
  3. 1
    1
      docs/content/search/_index.md

+ 1
- 1
archetypes/search.md View File

@@ -10,7 +10,7 @@ noindex = true # tell robots not to index
10 10
   disabled = false
11 11
 [security.csp.directives]
12 12
   scriptSrc = [
13
-    "'sha512-/RBCDeYFF/rhDFH6gLtx6zZUXN92hCNlE/FRjG9d4KrijurUGd/79Poe07qs7CBadFV6SqXlC0bWZ+Gn2OLkDA=='",
13
+    "'sha512-6G7cmlXR4eLBphfUmmEWLEnLWSEtZPdKP2xv7bXZ8D3LReZazwxcwb4tTx2HeCeoAChG5ZCE+UqHmbe3K4xoJg=='",
14 14
     "'unsafe-eval'"
15 15
   ]
16 16
 +++

+ 3
- 1
assets/js/search.js View File

@@ -12,7 +12,7 @@ fetchInject([
12 12
     ).replace(/\+/g, ' ');
13 13
 
14 14
     const queryParam = 's';
15
-    const hotkeys = '{{ .Params.form.hotkeys | default (slice "/" "s") }}';
15
+    const hotkeys = {{ (.Params.form.hotkeys | default (slice "/" "s")) | jsonify }};
16 16
     const selectors = {
17 17
       appContainer: '#search-app',
18 18
       resultContainer: '#search-results',
@@ -73,7 +73,9 @@ fetchInject([
73 73
         window.onpopstate = (evt) => {
74 74
           this.query = evt.state.query;
75 75
         };
76
+        const searchInput = getSearchInput();
76 77
         document.onkeydown = function (evt) {
78
+          if (evt.target === searchInput) return;
77 79
           if (hotkeys.includes(evt.key)) {
78 80
             evt.preventDefault();
79 81
             focusSearchInput();

+ 1
- 1
docs/content/search/_index.md View File

@@ -10,7 +10,7 @@ noindex = true # tell robots not to index
10 10
   disabled = false
11 11
 [security.csp.directives]
12 12
   scriptSrc = [
13
-    "'sha512-/RBCDeYFF/rhDFH6gLtx6zZUXN92hCNlE/FRjG9d4KrijurUGd/79Poe07qs7CBadFV6SqXlC0bWZ+Gn2OLkDA=='",
13
+    "'sha512-6G7cmlXR4eLBphfUmmEWLEnLWSEtZPdKP2xv7bXZ8D3LReZazwxcwb4tTx2HeCeoAChG5ZCE+UqHmbe3K4xoJg=='",
14 14
     "'unsafe-eval'"
15 15
   ]
16 16
 +++

Loading…
Cancel
Save