From 6f215381f791ebf6c05c4232d6703a4ddc553650 Mon Sep 17 00:00:00 2001 From: Martin Fischer Date: Sat, 27 Nov 2021 10:34:40 +0100 Subject: search: implement --- script.js | 23 +++++++++++++++++++++-- 1 file 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) => `${x}`); + a.href = feat.url; + li.appendChild(a); + ul.appendChild(li); + } + document.getElementById(key + '-list').replaceChildren(...ul.children); + } + }); })(); -- cgit v1.2.3