1 line
713 B
JavaScript
1 line
713 B
JavaScript
(async function(){const t=e=>e.toLowerCase().split(/([^a-z]|[^\x00-\x7F])/),n=new FlexSearch.Document({cache:!0,charset:"latin:extra",optimize:!0,index:[{field:"content",tokenize:"reverse",encode:t},{field:"title",tokenize:"forward",encode:t}]}),{content:e}=await fetchData;for(const[s,t]of Object.entries(e))n.add({id:s,title:t.title,content:removeMarkdown(t.content)});const s=t=>({id:t,url:t,title:e[t].title,content:e[t].content});registerHandlers(e=>{const t=e.target.value,i=n.search(t,[{field:"content",limit:10},{field:"title",limit:5}]),o=e=>{const t=i.filter(t=>t.field===e);return t.length===0?[]:[...t[0].result]},a=new Set([...o("title"),...o("content")]),r=[...a].map(s);displayResults(t,r,!0)})})() |