Jacky Zhao
2023-08-19 c874e7e9378a5ba895870e9680484fb4af5c6e93
quartz/components/scripts/spa.inline.ts
@@ -1,5 +1,5 @@
import micromorph from "micromorph"
import { CanonicalSlug, RelativeURL, getCanonicalSlug } from "../../util/path"
import { FullSlug, RelativeURL, getFullSlug } from "../../util/path"
// adapted from `micromorph`
// https://github.com/natemoo-re/micromorph
@@ -31,7 +31,7 @@
  return { url: new URL(href), scroll: "routerNoscroll" in a.dataset ? false : undefined }
}
function notifyNav(url: CanonicalSlug) {
function notifyNav(url: FullSlug) {
  const event: CustomEventMap["nav"] = new CustomEvent("nav", { detail: { url } })
  document.dispatchEvent(event)
}
@@ -81,7 +81,7 @@
  const elementsToAdd = html.head.querySelectorAll(":not([spa-preserve])")
  elementsToAdd.forEach((el) => document.head.appendChild(el))
  notifyNav(getCanonicalSlug(window))
  notifyNav(getFullSlug(window))
  delete announcer.dataset.persist
}
@@ -129,7 +129,7 @@
}
createRouter()
notifyNav(getCanonicalSlug(window))
notifyNav(getFullSlug(window))
if (!customElements.get("route-announcer")) {
  const attrs = {