Skip to content

Commit

Permalink
🔄 synced local 'quartz/' with remote 'quartz/'
Browse files Browse the repository at this point in the history
  • Loading branch information
Mara-Li committed Feb 15, 2024
1 parent 96ad552 commit 38941ef
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 11 deletions.
40 changes: 29 additions & 11 deletions quartz/components/scripts/popover.inline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,29 +37,47 @@ async function mouseEnterHandler(
targetUrl.hash = ""
targetUrl.search = ""

const contents = await fetch(`${targetUrl}`)
.then((res) => res.text())
.catch((err) => {
console.error(err)
})
const response = await fetch(`${targetUrl}`).catch((err) => {
console.error(err)
})

// bailout if another popover exists
if (hasAlreadyBeenFetched()) {
return
}

if (!contents) return
const html = p.parseFromString(contents, "text/html")
normalizeRelativeURLs(html, targetUrl)
const elts = [...html.getElementsByClassName("popover-hint")]
if (elts.length === 0) return
if (!response) return
const contentType = response.headers.get("Content-Type")
const contentTypeCategory = contentType?.split("/")[0] ?? "text"

const popoverElement = document.createElement("div")
popoverElement.classList.add("popover")
const popoverInner = document.createElement("div")
popoverInner.classList.add("popover-inner")
popoverElement.appendChild(popoverInner)
elts.forEach((elt) => popoverInner.appendChild(elt))

popoverInner.dataset.contentType = contentTypeCategory

switch (contentTypeCategory) {
case "image":
const img = document.createElement("img")

response.blob().then((blob) => {
img.src = URL.createObjectURL(blob)
})
img.alt = targetUrl.pathname

popoverInner.appendChild(img)
break
default:
const contents = await response.text()
const html = p.parseFromString(contents, "text/html")
normalizeRelativeURLs(html, targetUrl)
const elts = [...html.getElementsByClassName("popover-hint")]
if (elts.length === 0) return

elts.forEach((elt) => popoverInner.appendChild(elt))
}

setPosition(popoverElement)
link.appendChild(popoverElement)
Expand Down
11 changes: 11 additions & 0 deletions quartz/components/styles/popover.scss
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@
white-space: normal;
}

& > .popover-inner[data-content-type="image"] {
padding: 0;
max-height: 100%;

img {
margin: 0;
border-radius: 0;
display: block;
}
}

h1 {
font-size: 1.5rem;
}
Expand Down

0 comments on commit 38941ef

Please sign in to comment.