Browse Source

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

jsonify hotkeys passed from go-html-templates for use in javascript
pull/149/head
Josh Habdas 1 year ago
parent
commit
630d3a9339
Signed by: jhabdas 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
disabled = false
[security.csp.directives]
scriptSrc = [
"'sha512-/RBCDeYFF/rhDFH6gLtx6zZUXN92hCNlE/FRjG9d4KrijurUGd/79Poe07qs7CBadFV6SqXlC0bWZ+Gn2OLkDA=='",
"'sha512-6G7cmlXR4eLBphfUmmEWLEnLWSEtZPdKP2xv7bXZ8D3LReZazwxcwb4tTx2HeCeoAChG5ZCE+UqHmbe3K4xoJg=='",
"'unsafe-eval'"
]
+++

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

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

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

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

Loading…
Cancel
Save