diff options
| author | Mitja Felicijan <mitja.felicijan@gmail.com> | 2024-10-15 14:23:31 +0200 |
|---|---|---|
| committer | Mitja Felicijan <mitja.felicijan@gmail.com> | 2024-10-15 14:23:31 +0200 |
| commit | 3e1fbbe545d2e15823d7f770621fc68b71f2d8d9 (patch) | |
| tree | 4b7a26756590060194975d0150720a01e7eb7842 /templates/index.html | |
| parent | e4b2890d0d064fe85ec1b800271a5fd0e2ef8fda (diff) | |
| download | mitjafelicijan.com-3e1fbbe545d2e15823d7f770621fc68b71f2d8d9.tar.gz | |
Added search boxes for posts and notes
Diffstat (limited to 'templates/index.html')
| -rw-r--r-- | templates/index.html | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/templates/index.html b/templates/index.html index f5821fc..e3586ff 100644 --- a/templates/index.html +++ b/templates/index.html | |||
| @@ -11,6 +11,40 @@ | |||
| 11 | bytes (trigraphs). | 11 | bytes (trigraphs). |
| 12 | </a> | 12 | </a> |
| 13 | 13 | ||
| 14 | <section class="quick-jump"> | ||
| 15 | <input list="qj-posts" placeholder="Search for posts"> | ||
| 16 | <datalist id="qj-posts"> | ||
| 17 | {{ range .Pages }} | ||
| 18 | {{ if and (eq .Type "post") (not .Draft) }} | ||
| 19 | <option data-url="{{ .RelPermalink }}">{{ .Title }}</option> | ||
| 20 | {{ end }} | ||
| 21 | {{ end }} | ||
| 22 | </datalist> | ||
| 23 | <input list="qj-notes" placeholder="Search for notes"> | ||
| 24 | <datalist id="qj-notes"> | ||
| 25 | {{ range .Pages }} | ||
| 26 | {{ if and (eq .Type "note") (not .Draft) }} | ||
| 27 | <option data-url="{{ .RelPermalink }}">{{ .Title }}</option> | ||
| 28 | {{ end }} | ||
| 29 | {{ end }} | ||
| 30 | </datalist> | ||
| 31 | </section> | ||
| 32 | |||
| 33 | <script> | ||
| 34 | document.querySelectorAll("section.quick-jump input[list]").forEach(s => { | ||
| 35 | s.addEventListener("change", e => { | ||
| 36 | const input = e.target; | ||
| 37 | const datalist = e.target.list; | ||
| 38 | for (var j = 0; j < datalist.options.length; j++) { | ||
| 39 | if (input.value == datalist.options[j].value) { | ||
| 40 | console.log(input.value, datalist.options[j].dataset.url); | ||
| 41 | window.location.href = `/${datalist.options[j].dataset.url}`; | ||
| 42 | } | ||
| 43 | } | ||
| 44 | }); | ||
| 45 | }); | ||
| 46 | </script> | ||
| 47 | |||
| 14 | <section> | 48 | <section> |
| 15 | <h2>More long form, ramblings etc</h2> | 49 | <h2>More long form, ramblings etc</h2> |
| 16 | <ul itemscope itemtype="https://schema.org/SiteNavigationElement" role="list" aria-label="More long form, ramblings etc"> | 50 | <ul itemscope itemtype="https://schema.org/SiteNavigationElement" role="list" aria-label="More long form, ramblings etc"> |
