aboutsummaryrefslogtreecommitdiff
path: root/themes/simple/layouts/_default/notes.html
diff options
context:
space:
mode:
authorMitja Felicijan <mitja.felicijan@gmail.com>2023-05-24 16:26:59 +0200
committerMitja Felicijan <mitja.felicijan@gmail.com>2023-05-24 16:26:59 +0200
commit1553304b890b12eba606d0fa0eac7cfbfc4466b4 (patch)
tree20c473f07aec7da84aa9af6dba41a5eff1af2815 /themes/simple/layouts/_default/notes.html
parent3540b9210f1f382a1c4d3e1f7da30571d0633e21 (diff)
downloadmitjafelicijan.com-1553304b890b12eba606d0fa0eac7cfbfc4466b4.tar.gz
Added jump to note dropdown on notes
Diffstat (limited to 'themes/simple/layouts/_default/notes.html')
-rw-r--r--themes/simple/layouts/_default/notes.html30
1 files changed, 29 insertions, 1 deletions
diff --git a/themes/simple/layouts/_default/notes.html b/themes/simple/layouts/_default/notes.html
index ea42c32..a3a6bab 100644
--- a/themes/simple/layouts/_default/notes.html
+++ b/themes/simple/layouts/_default/notes.html
@@ -11,7 +11,11 @@
11 </p> 11 </p>
12 </section> 12 </section>
13 13
14 <hr class="border-2 border-gray-100 mb-12"> 14 <hr class="border-2 border-gray-100 mb-8">
15
16 <select id="jump-to-note" class="px-3 py-2 rounded mb-2">
17 <option>Jump to note</option>
18 </select>
15 19
16 <!-- List of all notes --> 20 <!-- List of all notes -->
17 <nav itemscope itemtype="https://schema.org/SiteNavigationElement" class="mb-12" role="feed"> 21 <nav itemscope itemtype="https://schema.org/SiteNavigationElement" class="mb-12" role="feed">
@@ -47,5 +51,29 @@
47 </section> 51 </section>
48 </nav> 52 </nav>
49 53
54 <script>
55 try {
56 const notes = document.querySelectorAll('h2');
57 const select = document.querySelector('#jump-to-note');
58
59 notes.forEach(note => {
60 const id = note.innerText.toLowerCase().replace(/ /g, '-').replace(/[^\w-]+/g, '');
61 note.id = id;
62 note.innerHTML = `<a href="#${id}"></a>${note.innerHTML}`;
63
64 const option = document.createElement('option');
65 option.value = id;
66 option.innerText = note.innerText;
67 select.appendChild(option);
68
69 select.addEventListener('change', () => {
70 window.location.hash = select.value;
71 });
72 });
73 } catch (error) {
74 console.error(error);
75 }
76 </script>
77
50</main> 78</main>
51{{ end }} 79{{ end }}