PageSourceSearch

https://zerx.dev/_astro/BlogSearchBox.astro_astro_type_script_index_0_lang.DihFR4Dk.js

js zerx.dev collected 2026-10-01 15:19:11 UTC 4,144 bytes, 1 lines download raw bytes

1import{u as w}from"./ui.XsTdHkqH.js";const $={"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"};function f(e){return e?e.replace(/[&<>"']/g,t=>$[t]??t):""}function T(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function _(e,t){const a=e??"",n=(t??"").trim();if(a.length===0)return"";if(n.length===0)return f(a);let i;try{i=new RegExp(T(n),"gi")}catch{return f(a)}if(i.source.length===0)return f(a);let r="",c=0;for(const l of a.matchAll(i)){const o=l.index??-1;if(o<0)continue;const u=o+l[0].length;o>c&&(r+=f(a.slice(c,o))),r+=`<mark class="search-hit">${f(l[0])}</mark>`,c=u}return c<a.length&&(r+=f(a.slice(c))),r.length===0?f(a):r}function B(e){const t=typeof e=="string"?new Date(e):e;if(Number.isNaN(t.getTime()))return"";const a=t.getFullYear(),n=String(t.getMonth()+1).padStart(2,"0"),i=String(t.getDate()).padStart(2,"0");return`${a}-${n}-${i}`}const S=new Map;function I(e){let t=S.get(e);return t||(t=fetch(`/search/${e}.json`).then(a=>a.ok?a.json():[]).catch(()=>[]),S.set(e,t)),t}function k(e,t,a,n,i){const r=document.createElement("a");r.href=`${a}/${e.slug}/`,r.className="search-result-card",r.style.setProperty("--i",String(Math.min(i,8)));const c=document.createElement("div");c.className="search-result-card__side";const l=document.createElement("time");l.className="search-result-card__date";const o=new Date(e.date);if(Number.isNaN(o.getTime())||(l.dateTime=o.toISOString()),l.textContent=B(e.date).replaceAll("-","."),c.append(l),e.categoryName){const s=document.createElement("span");s.className="search-result-card__cat",s.textContent=e.categoryName,c.append(s)}const u=document.createElement("div");u.className="search-result-card__body";const m=document.createElement("h3");m.className="search-result-card__title",m.innerHTML=_(e.title,t);const g=document.createElement("p");if(g.className="search-result-card__excerpt",g.innerHTML=_(e.excerpt,t),u.append(m,g),e.readingTime>0){const s=document.createElement("span");s.className="search-result-card__meta",s.textContent=`${e.readingTime} ${w[n]["blog.minutes"]}`,u.append(s)}return r.append(c,u),r}function M(e){if(e.__blogSearchInitialized)return;e.__blogSearchInitialized=!0;const t=e.querySelector("[data-blog-search-toggle]"),a=e.querySelector("[data-blog-search-panel]"),n=e.querySelector("[data-blog-search-input]"),i=e.querySelector("[data-blog-search-clear]");if(!t||!a||!n)return;const r=e.getAttribute("data-lang")??"zh",c=e.getAttribute("data-list-base")??"/blog",l=document.getElementById("post-grid"),o=document.getElementById("blog-pagination"),u=document.getElementById("blog-category-tabs"),m=document.getElementById("search-results"),g=document.getElementById("search-empty");function s(d,h=!1){e.setAttribute("data-expanded",d?"true":"false"),t.setAttribute("aria-expanded",d?"true":"false"),d&&h&&requestAnimationFrame(()=>n.focus())}function p(){i&&(i.hidden=n.value.length===0)}function N(){m?.setAttribute("hidden",""),g?.setAttribute("hidden",""),l?.removeAttribute("hidden"),o?.removeAttribute("hidden"),u?.removeAttribute("hidden")}function x(){l?.setAttribute("hidden",""),o?.setAttribute("hidden",""),u?.setAttribute("hidden","")}async function b(d){const h=d.trim();if(h.length===0){N();return}x();const v=h.toLowerCase(),C=await I(r);if(n.value.trim().toLowerCase()!==v||!m||!g)return;const A=C.filter(y=>y.text.includes(v));m.replaceChildren(...A.map((y,L)=>k(y,h,c,r,L))),A.length===0?(m.setAttribute("hidden",""),g.removeAttribute("hidden")):(m.removeAttribute("hidden"),g.setAttribute("hidden",""))}s(!1),p(),t.addEventListener("click",()=>{s(!0,!0)}),n.addEventListener("input",()=>{p(),b(n.value)}),i?.addEventListener("click",()=>{n.value="",p(),b(""),n.focus()}),n.addEventListener("keydown",d=>{d.key==="Escape"&&(n.value.length>0?(n.value="",p(),b(""),d.preventDefault()):(s(!1),t.focus()))}),document.addEventListener("click",d=>{const h=d.target;h&&(e.contains(h)||n.value.length===0&&s(!1))},{capture:!0})}function E(){document.querySelectorAll("[data-blog-search]").forEach(M)}document.readyState==="loading"?document.addEventListener("DOMContentLoaded",E):E();document.addEventListener("astro:page-load",E);

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.