mirror of
https://github.com/jackyzha0/quartz.git
synced 2025-12-24 13:24:05 -06:00
9 lines
1.2 KiB
JavaScript
9 lines
1.2 KiB
JavaScript
function htmlToElement(e){const t=document.createElement("template");return e=e.trim(),t.innerHTML=e,t.content.firstChild}function initPopover(e,t,n){const s=e.replace(window.location.origin,"");fetchData.then(({content:e})=>{const o=[...document.getElementsByClassName("internal-link")];o.filter(e=>e.dataset.src||e.dataset.idx&&t).forEach(t=>{var o;if(t.dataset.ctx){const n=e[t.dataset.src],s=`<div class="popover">
|
|
<h3>${n.title}</h3>
|
|
<p>${highlight(removeMarkdown(n.content),t.dataset.ctx)}...</p>
|
|
<p class="meta">${new Date(n.lastmodified).toLocaleDateString()}</p>
|
|
</div>`;o=htmlToElement(s)}else{const n=e[t.dataset.src.replace(/\/$/g,"").replace(s,"")];if(console.log(n.content),n){const e=`<div class="popover">
|
|
<h3>${n.title}</h3>
|
|
<p>${removeMarkdown(n.content).split(" ",20).join(" ")}...</p>
|
|
<p class="meta">${new Date(n.lastmodified).toLocaleDateString()}</p>
|
|
</div>`;o=htmlToElement(e)}}t.appendChild(o),n&&renderMathInElement(o,{delimiters:[{left:"$$",right:"$$",display:!1},{left:"$",right:"$",display:!1},{left:"\\(",right:"\\)",display:!1},{left:"\\[",right:"\\]",display:!1}],throwOnError:!1}),t.addEventListener("mouseover",()=>{o.classList.add("visible")}),t.addEventListener("mouseout",()=>{o.classList.remove("visible")})})})} |