summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2021-11-27 10:34:40 +0100
committerMartin Fischer <martin@push-f.com>2021-11-27 12:54:09 +0100
commit6f215381f791ebf6c05c4232d6703a4ddc553650 (patch)
tree99d056d1b5fb27aa86b7dff787905c0f1e59822f
parent472049655854be85acc4e2cd8fd920914d24ecd7 (diff)
search: implement
-rw-r--r--script.js23
1 files changed, 21 insertions, 2 deletions
diff --git a/script.js b/script.js
index 67018f7..fce62e0 100644
--- a/script.js
+++ b/script.js
@@ -1,6 +1,25 @@
(async function(){
const res = await fetch('data.json');
- const data = await res.json();
+ const versions = await res.json();
- // TODO: implement search
+ const input = document.getElementById('search');
+ input.addEventListener('input', (e) => {
+ const query = e.target.value;
+ for (const [key, data] of Object.entries(versions)) {
+ const results = Object.values(data.features).filter(
+ feat => feat.title.toLowerCase().replaceAll('`', '').includes(query.toLowerCase())
+ );
+ const ul = document.createElement('ul');
+ for (const feat of results) {
+ const li = document.createElement('li');
+ const a = document.createElement('a');
+ a.textContent = feat.title;
+ a.innerHTML = a.innerHTML.replaceAll(/`(.+?)`/g, (_, x) => `<code>${x}</code>`);
+ a.href = feat.url;
+ li.appendChild(a);
+ ul.appendChild(li);
+ }
+ document.getElementById(key + '-list').replaceChildren(...ul.children);
+ }
+ });
})();