From 906f91f8eed5e91a7afae95c7002a3e4553d6aae Mon Sep 17 00:00:00 2001
From: Jacky Zhao <j.zhao2k19@gmail.com>
Date: Thu, 13 Jul 2023 07:19:35 +0000
Subject: [PATCH] base path refactor, more docs
---
quartz/components/scripts/spa.inline.ts | 11 ++++++++---
1 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/quartz/components/scripts/spa.inline.ts b/quartz/components/scripts/spa.inline.ts
index da34700..5ba53e3 100644
--- a/quartz/components/scripts/spa.inline.ts
+++ b/quartz/components/scripts/spa.inline.ts
@@ -1,4 +1,5 @@
import micromorph from "micromorph"
+import { CanonicalSlug, RelativeURL } from "../../path"
// adapted from `micromorph`
// https://github.com/natemoo-re/micromorph
@@ -29,8 +30,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: CanonicalSlug) {
+ const event: CustomEventMap["nav"] = new CustomEvent("nav", { detail: { url } })
document.dispatchEvent(event)
}
@@ -73,6 +74,8 @@
delete announcer.dataset.persist
}
+window.spaNavigate = navigate
+
function createRouter() {
if (typeof window !== "undefined") {
window.addEventListener("click", async (event) => {
@@ -96,8 +99,9 @@
return
})
}
+
return new class Router {
- go(pathname: string) {
+ go(pathname: RelativeURL) {
const url = new URL(pathname, window.location.toString())
return navigate(url, false)
}
@@ -113,6 +117,7 @@
}
createRouter()
+notifyNav(document.body.dataset.slug!)
if (!customElements.get('route-announcer')) {
const attrs = {
--
Gitblit v1.10.0