From 6a05fa777c3830631d8aeb16bdda287a1fea3b80 Mon Sep 17 00:00:00 2001 From: Jacky Zhao Date: Fri, 17 Nov 2023 14:00:49 -0800 Subject: [PATCH 1/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 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 2/4] 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 3/4] 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 4/4] 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 (