Jacky Zhao
2023-07-07 b3480bdc49120010da8d2805df02cbf84ca08bdc
quartz/components/scripts/spa.inline.ts
@@ -29,8 +29,8 @@
  return { url: new URL(href), scroll: 'routerNoscroll' in a.dataset ? false : undefined }
}
function notifyNav(slug: string) {
  const event = new CustomEvent("spa_nav", { detail: { slug } })
function notifyNav(url: string) {
  const event: CustomEventMap["nav"] = new CustomEvent("nav", { detail: { url } })
  document.dispatchEvent(event)
}
@@ -73,6 +73,8 @@
  delete announcer.dataset.persist
}
window.spaNavigate = navigate
function createRouter() {
  if (typeof window !== "undefined") {
    window.addEventListener("click", async (event) => {
@@ -96,6 +98,7 @@
      return
    })
  }
  return new class Router {
    go(pathname: string) {
      const url = new URL(pathname, window.location.toString())
@@ -113,6 +116,7 @@
}
createRouter()
notifyNav(document.body.dataset.slug!)
if (!customElements.get('route-announcer')) {
  const attrs = {