From 563ab4aaaf8e680968a67e02c3659736fbec0cf7 Mon Sep 17 00:00:00 2001
From: Jacky Zhao <j.zhao2k19@gmail.com>
Date: Tue, 06 Aug 2024 01:49:20 +0000
Subject: [PATCH] docs: update node version in hosting docs

---
 quartz/components/scripts/popover.inline.ts |   28 ++++++++++++++++++----------
 1 files changed, 18 insertions(+), 10 deletions(-)

diff --git a/quartz/components/scripts/popover.inline.ts b/quartz/components/scripts/popover.inline.ts
index d0346b0..49f4382 100644
--- a/quartz/components/scripts/popover.inline.ts
+++ b/quartz/components/scripts/popover.inline.ts
@@ -3,7 +3,7 @@
 
 const p = new DOMParser()
 async function mouseEnterHandler(
-  this: HTMLLinkElement,
+  this: HTMLAnchorElement,
   { clientX, clientY }: { clientX: number; clientY: number },
 ) {
   const link = this
@@ -33,7 +33,7 @@
   thisUrl.hash = ""
   thisUrl.search = ""
   const targetUrl = new URL(link.href)
-  const hash = targetUrl.hash
+  const hash = decodeURIComponent(targetUrl.hash)
   targetUrl.hash = ""
   targetUrl.search = ""
 
@@ -47,8 +47,8 @@
   }
 
   if (!response) return
-  const contentType = response.headers.get("Content-Type")
-  const contentTypeCategory = contentType?.split("/")[0] ?? "text"
+  const [contentType] = response.headers.get("Content-Type")!.split(";")
+  const [contentTypeCategory, typeInfo] = contentType.split("/")
 
   const popoverElement = document.createElement("div")
   popoverElement.classList.add("popover")
@@ -56,19 +56,27 @@
   popoverInner.classList.add("popover-inner")
   popoverElement.appendChild(popoverInner)
 
-  popoverInner.dataset.contentType = contentTypeCategory
+  popoverInner.dataset.contentType = contentType ?? undefined
 
   switch (contentTypeCategory) {
     case "image":
       const img = document.createElement("img")
-
-      response.blob().then((blob) => {
-        img.src = URL.createObjectURL(blob)
-      })
+      img.src = targetUrl.toString()
       img.alt = targetUrl.pathname
 
       popoverInner.appendChild(img)
       break
+    case "application":
+      switch (typeInfo) {
+        case "pdf":
+          const pdf = document.createElement("iframe")
+          pdf.src = targetUrl.toString()
+          popoverInner.appendChild(pdf)
+          break
+        default:
+          break
+      }
+      break
     default:
       const contents = await response.text()
       const html = p.parseFromString(contents, "text/html")
@@ -92,7 +100,7 @@
 }
 
 document.addEventListener("nav", () => {
-  const links = [...document.getElementsByClassName("internal")] as HTMLLinkElement[]
+  const links = [...document.getElementsByClassName("internal")] as HTMLAnchorElement[]
   for (const link of links) {
     link.addEventListener("mouseenter", mouseEnterHandler)
     window.addCleanup(() => link.removeEventListener("mouseenter", mouseEnterHandler))

--
Gitblit v1.10.0