base path refactor to better support subpath hosting

This commit is contained in:
Jacky Zhao 2023-08-19 15:52:25 -07:00
parent 3201f83b70
commit c874e7e937
29 changed files with 257 additions and 389 deletions
quartz/components/scripts

View file

@ -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 @@ const getOpts = ({ target }: Event): { url: URL; scroll?: boolean } | undefined
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 @@ async function navigate(url: URL, isBack: boolean = false) {
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 @@ function createRouter() {
}
createRouter()
notifyNav(getCanonicalSlug(window))
notifyNav(getFullSlug(window))
if (!customElements.get("route-announcer")) {
const attrs = {