PageSourceSearch

https://readingohio.org/assets/search.js?v=17

js readingohio.org collected 2026-10-02 19:57:05 UTC 1,742 bytes, 25 lines download raw bytes

1/* readingohio.org site search: one fetch of a static index, no server. */
2(function(){var box=document.getElementById("results"),f=document.getElementById("sitesearch");
3if(!box||!f)return;var input=f.querySelector("input[name=q]"),idx=null;
4function esc(s){return s.replace(/[&<>"]/g,function(c){
5return {"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;"}[c];});}
6function q(){return (new URLSearchParams(location.search)).get("q")||"";}
7function run(term){term=(term||"").trim();if(!term){box.innerHTML="";return;}
8var words=term.toLowerCase().split(/\s+/).filter(Boolean);
9var hits=idx.map(function(r){var hay=(r.t+" "+r.x).toLowerCase(),s=0;
10words.forEach(function(w){if(r.t.toLowerCase().indexOf(w)>=0)s+=8;
11var n=hay.split(w).length-1;s+=Math.min(n,6);});return {r:r,s:s};})
12.filter(function(h){return h.s>0;}).sort(function(a,b){return b.s-a.s;}).slice(0,40);
13if(!hits.length){box.innerHTML="<p>Nothing matched <strong>"+esc(term)+
14"</strong>. Try a single word, or browse the menu above.</p>";return;}
15box.innerHTML="<p>"+hits.length+(hits.length===1?" page":" pages")+" matching <strong>"+
16esc(term)+"</strong></p><div class=\"newslist\">"+hits.map(function(h){
17var r=h.r,i=r.x.toLowerCase().indexOf(words[0]),snip=r.x.slice(Math.max(0,i-70),
18Math.max(0,i-70)+220);return "<article class=\"newsitem\"><h3><a href=\""+
19esc(r.u)+"\">"+esc(r.t)+"</a></h3><p>"+esc(snip)+"\u2026</p></article>";})
20.join("")+"</div>";}
21f.addEventListener("submit",function(e){e.preventDefault();
22history.replaceState(null,"","/search.aspx?q="+encodeURIComponent(input.value));
23if(idx)run(input.value);});
24fetch("/assets/search-index.json").then(function(r){return r.json();}).then(function(j){
25idx=j;input.value=q();if(input.value)run(input.value);});})();

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.