From 727b9b5d72464d26427a8bdf3ab06e522e67b21c Mon Sep 17 00:00:00 2001 From: Matt Vogel Date: Fri, 17 Nov 2023 13:23:39 -0500 Subject: [PATCH 1/7] 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 8d16136f3c66a..eec473c103c38 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/7] 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 9fe18654fd1b0..72404ed238640 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/7] 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 c0152b52d2fe2..29cc334480697 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/7] 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 e9510bb2ffd81..2e47cedf56d79 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}]]` }) From 516d9a27e7e2c08efdf24857b03f1831dbaf7da7 Mon Sep 17 00:00:00 2001 From: Jacky Zhao Date: Sat, 18 Nov 2023 18:27:44 -0800 Subject: [PATCH 5/7] fix: explicit undefined check in header transclude --- quartz/components/renderPage.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/quartz/components/renderPage.tsx b/quartz/components/renderPage.tsx index 36b06464f44f5..5cb39d9ad6963 100644 --- a/quartz/components/renderPage.tsx +++ b/quartz/components/renderPage.tsx @@ -104,7 +104,7 @@ export function renderPage( break } - if (startIdx) { + if (startIdx !== undefined) { endIdx = i } else if (el.properties?.id === blockRef) { startIdx = i @@ -112,7 +112,7 @@ export function renderPage( } } - if (!startIdx) { + if (startIdx === undefined) { return } From 296c1cf83f587706d23ffc2f14962628d0534953 Mon Sep 17 00:00:00 2001 From: Jacky Zhao Date: Sat, 18 Nov 2023 18:46:58 -0800 Subject: [PATCH 6/7] fix: spa shouldn't use popover script directly --- quartz/components/scripts/popover.inline.ts | 17 +---------------- quartz/components/scripts/spa.inline.ts | 4 +--- quartz/util/path.ts | 16 ++++++++++++++++ 3 files changed, 18 insertions(+), 19 deletions(-) diff --git a/quartz/components/scripts/popover.inline.ts b/quartz/components/scripts/popover.inline.ts index 2bd21d1eb14fa..371563ba9fcb2 100644 --- a/quartz/components/scripts/popover.inline.ts +++ b/quartz/components/scripts/popover.inline.ts @@ -1,20 +1,5 @@ import { computePosition, flip, inline, shift } from "@floating-ui/dom" - -// from micromorph/src/utils.ts -// https://github.com/natemoo-re/micromorph/blob/main/src/utils.ts#L5 -export function normalizeRelativeURLs(el: Element | Document, destination: string | URL) { - const rebase = (el: Element, attr: string, newBase: string | URL) => { - const rebased = new URL(el.getAttribute(attr)!, newBase) - el.setAttribute(attr, rebased.pathname + rebased.hash) - } - - el.querySelectorAll('[href^="./"], [href^="../"]').forEach((item) => - rebase(item, "href", destination), - ) - el.querySelectorAll('[src^="./"], [src^="../"]').forEach((item) => - rebase(item, "src", destination), - ) -} +import { normalizeRelativeURLs } from "../../util/path" const p = new DOMParser() async function mouseEnterHandler( diff --git a/quartz/components/scripts/spa.inline.ts b/quartz/components/scripts/spa.inline.ts index 29cc334480697..c2a44c9a8bb62 100644 --- a/quartz/components/scripts/spa.inline.ts +++ b/quartz/components/scripts/spa.inline.ts @@ -1,10 +1,8 @@ import micromorph from "micromorph" -import { FullSlug, RelativeURL, getFullSlug } from "../../util/path" -import { normalizeRelativeURLs } from "./popover.inline" +import { FullSlug, RelativeURL, getFullSlug, normalizeRelativeURLs } from "../../util/path" // adapted from `micromorph` // https://github.com/natemoo-re/micromorph - const NODE_TYPE_ELEMENT = 1 let announcer = document.createElement("route-announcer") const isElement = (target: EventTarget | null): target is Element => diff --git a/quartz/util/path.ts b/quartz/util/path.ts index 173eb2ece952b..e450339fd1923 100644 --- a/quartz/util/path.ts +++ b/quartz/util/path.ts @@ -84,6 +84,22 @@ export function transformInternalLink(link: string): RelativeURL { return res } +// from micromorph/src/utils.ts +// https://github.com/natemoo-re/micromorph/blob/main/src/utils.ts#L5 +export function normalizeRelativeURLs(el: Element | Document, destination: string | URL) { + const rebase = (el: Element, attr: string, newBase: string | URL) => { + const rebased = new URL(el.getAttribute(attr)!, newBase) + el.setAttribute(attr, rebased.pathname + rebased.hash) + } + + el.querySelectorAll('[href^="./"], [href^="../"]').forEach((item) => + rebase(item, "href", destination), + ) + el.querySelectorAll('[src^="./"], [src^="../"]').forEach((item) => + rebase(item, "src", destination), + ) +} + // resolve /a/b/c to ../.. export function pathToRoot(slug: FullSlug): RelativeURL { let rootPath = slug From 9a599aebeada7f95170dac98c3f30023d9e7453f Mon Sep 17 00:00:00 2001 From: Rune Antonsen Date: Mon, 20 Nov 2023 17:28:16 +0100 Subject: [PATCH 7/7] feat(breadcrumbs): add option to hide current page (#601) * feat(breadcrumbs): add option to hide current page * Remove debug lines Co-authored-by: Jacky Zhao --------- Co-authored-by: ruant Co-authored-by: Jacky Zhao --- docs/features/breadcrumbs.md | 1 + quartz/components/Breadcrumbs.tsx | 15 +++++++++++---- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/docs/features/breadcrumbs.md b/docs/features/breadcrumbs.md index 20c3b8d65605c..a241aac41a054 100644 --- a/docs/features/breadcrumbs.md +++ b/docs/features/breadcrumbs.md @@ -20,6 +20,7 @@ Component.Breadcrumbs({ rootName: "Home", // name of first/root element resolveFrontmatterTitle: true, // whether to resolve folder names through frontmatter titles hideOnRoot: true, // whether to hide breadcrumbs on root `index.md` page + showCurrentPage: true, // wether to display the current page in the breadcrumbs }) ``` diff --git a/quartz/components/Breadcrumbs.tsx b/quartz/components/Breadcrumbs.tsx index 29c73a81b58b1..8998c406498a1 100644 --- a/quartz/components/Breadcrumbs.tsx +++ b/quartz/components/Breadcrumbs.tsx @@ -25,6 +25,10 @@ interface BreadcrumbOptions { * Wether to display breadcrumbs on root `index.md` */ hideOnRoot: boolean + /** + * Wether to display the current page in the breadcrumbs. + */ + showCurrentPage: boolean } const defaultOptions: BreadcrumbOptions = { @@ -32,6 +36,7 @@ const defaultOptions: BreadcrumbOptions = { rootName: "Home", resolveFrontmatterTitle: true, hideOnRoot: true, + showCurrentPage: true, } function formatCrumb(displayName: string, baseSlug: FullSlug, currentSlug: SimpleSlug): CrumbData { @@ -95,10 +100,12 @@ export default ((opts?: Partial) => { } // Add current file to crumb (can directly use frontmatter title) - crumbs.push({ - displayName: fileData.frontmatter!.title, - path: "", - }) + if (options.showCurrentPage) { + crumbs.push({ + displayName: fileData.frontmatter!.title, + path: "", + }) + } } return (