From 727b9b5d72464d26427a8bdf3ab06e522e67b21c Mon Sep 17 00:00:00 2001 From: Matt Vogel Date: Fri, 17 Nov 2023 13:23:39 -0500 Subject: [PATCH 1/4] feat: add class `alias` to aliases (#585) --- quartz/plugins/transformers/links.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/quartz/plugins/transformers/links.ts b/quartz/plugins/transformers/links.ts index 8d16136f3..eec473c10 100644 --- a/quartz/plugins/transformers/links.ts +++ b/quartz/plugins/transformers/links.ts @@ -54,6 +54,16 @@ export const CrawlLinks: QuartzTransformerPlugin | undefined> = node.properties.className ??= [] node.properties.className.push(isAbsoluteUrl(dest) ? "external" : "internal") + // Check if the link has alias text + if ( + node.children.length === 1 && + node.children[0].type === "text" && + node.children[0].value !== dest + ) { + // Add the 'alias' class if the text content is not the same as the href + node.properties.className.push("alias") + } + if (opts.openLinksInNewTab) { node.properties.target = "_blank" } From ea08c0511a084f9ed77d1503847f4834046e2695 Mon Sep 17 00:00:00 2001 From: Jacky Zhao Date: Fri, 17 Nov 2023 10:29:07 -0800 Subject: [PATCH 2/4] fix: dont run explorer scripts on non-explorer pages (closes #596) --- quartz/components/scripts/explorer.inline.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/quartz/components/scripts/explorer.inline.ts b/quartz/components/scripts/explorer.inline.ts index 9fe18654f..72404ed23 100644 --- a/quartz/components/scripts/explorer.inline.ts +++ b/quartz/components/scripts/explorer.inline.ts @@ -120,9 +120,9 @@ function setupExplorer() { } } }) - } else { + } else if (explorer?.dataset.tree) { // If tree is not in localStorage or config is disabled, use tree passed from Explorer as dataset - explorerState = JSON.parse(explorer?.dataset.tree as string) + explorerState = JSON.parse(explorer.dataset.tree) } } @@ -130,12 +130,13 @@ window.addEventListener("resize", setupExplorer) document.addEventListener("nav", () => { setupExplorer() - const explorerContent = document.getElementById("explorer-ul") + observer.disconnect() + // select pseudo element at end of list const lastItem = document.getElementById("explorer-end") - - observer.disconnect() - observer.observe(lastItem as Element) + if (lastItem) { + observer.observe(lastItem) + } }) /** From 3f0be7fbe470500a57c457ad1d1c039175330697 Mon Sep 17 00:00:00 2001 From: Jacky Zhao Date: Fri, 17 Nov 2023 10:46:23 -0800 Subject: [PATCH 3/4] fix: check content-type before applying spa patch (closes #597) --- quartz/components/scripts/spa.inline.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/quartz/components/scripts/spa.inline.ts b/quartz/components/scripts/spa.inline.ts index c0152b52d..29cc33448 100644 --- a/quartz/components/scripts/spa.inline.ts +++ b/quartz/components/scripts/spa.inline.ts @@ -45,7 +45,14 @@ let p: DOMParser async function navigate(url: URL, isBack: boolean = false) { p = p || new DOMParser() const contents = await fetch(`${url}`) - .then((res) => res.text()) + .then((res) => { + const contentType = res.headers.get("content-type") + if (contentType?.startsWith("text/html")) { + return res.text() + } else { + window.location.assign(url) + } + }) .catch(() => { window.location.assign(url) }) From 6a05fa777c3830631d8aeb16bdda287a1fea3b80 Mon Sep 17 00:00:00 2001 From: Jacky Zhao Date: Fri, 17 Nov 2023 14:00:49 -0800 Subject: [PATCH 4/4] fix: bad transform in wikilink pre-transform (closes #598) --- quartz/plugins/transformers/ofm.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/quartz/plugins/transformers/ofm.ts b/quartz/plugins/transformers/ofm.ts index e9510bb2f..2e47cedf5 100644 --- a/quartz/plugins/transformers/ofm.ts +++ b/quartz/plugins/transformers/ofm.ts @@ -183,7 +183,7 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin const fp = rawFp ?? "" const anchor = rawHeader?.trim().replace(/^#+/, "") const displayAnchor = anchor ? `#${slugAnchor(anchor)}` : "" - const displayAlias = rawAlias ?? anchor ?? "" + const displayAlias = rawAlias ?? rawHeader?.replace("#", "|") ?? "" const embedDisplay = value.startsWith("!") ? "!" : "" return `${embedDisplay}[[${fp}${displayAnchor}${displayAlias}]]` })