From 1f2ea96ae0700f1cd4267f9bac7a59a8962f961f Mon Sep 17 00:00:00 2001 From: Jacky Zhao Date: Sat, 20 Jan 2024 00:33:08 -0800 Subject: [PATCH 01/14] fix: allow dashes and underscores in block references (closes #712) --- 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 e1a719c6f..8c6f48890 100644 --- a/quartz/plugins/transformers/ofm.ts +++ b/quartz/plugins/transformers/ofm.ts @@ -130,7 +130,7 @@ const calloutLineRegex = new RegExp(/^> *\[\!\w+\][+-]?.*$/, "gm") // (?:[-_\p{L}\d\p{Z}])+ -> non-capturing group, non-empty string of (Unicode-aware) alpha-numeric characters and symbols, hyphens and/or underscores // (?:\/[-_\p{L}\d\p{Z}]+)*) -> non-capturing group, matches an arbitrary number of tag strings separated by "/" const tagRegex = new RegExp(/(?:^| )#((?:[-_\p{L}\p{Emoji}\d])+(?:\/[-_\p{L}\p{Emoji}\d]+)*)/, "gu") -const blockReferenceRegex = new RegExp(/\^([A-Za-z0-9]+)$/, "g") +const blockReferenceRegex = new RegExp(/\^([-_A-Za-z0-9]+)$/, "g") const ytLinkRegex = /^.*(youtu.be\/|v\/|u\/\w\/|embed\/|watch\?v=|\&v=)([^#\&\?]*).*/ const videoExtensionRegex = new RegExp(/\.(mp4|webm|ogg|avi|mov|flv|wmv|mkv|mpg|mpeg|3gp|m4v)$/) From c11395e7bcd75eef37b4f4e9c67dc9c6f912c0b7 Mon Sep 17 00:00:00 2001 From: LUCASTUCIOUS Date: Sat, 20 Jan 2024 22:18:35 +0100 Subject: [PATCH 02/14] feat: Add an option to display or not reading time from notes (#707) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add an option to display or not reading time from notes * Prettier (?) * Remove ContentMeta override from quartz.layout.ts * Make it positive ! 🌞 * Update quartz/components/ContentMeta.tsx --------- Co-authored-by: Jacky Zhao --- quartz/components/ContentMeta.tsx | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/quartz/components/ContentMeta.tsx b/quartz/components/ContentMeta.tsx index 21dc13f95..254c5d405 100644 --- a/quartz/components/ContentMeta.tsx +++ b/quartz/components/ContentMeta.tsx @@ -2,18 +2,37 @@ import { formatDate, getDate } from "./Date" import { QuartzComponentConstructor, QuartzComponentProps } from "./types" import readingTime from "reading-time" -export default (() => { +interface ContentMetaOptions { + /** + * Whether to display reading time + */ + showReadingTime: boolean +} + +const defaultOptions: ContentMetaOptions = { + showReadingTime: true, +} + +export default ((opts?: Partial) => { + // Merge options with defaults + const options: ContentMetaOptions = { ...defaultOptions, ...opts } + function ContentMetadata({ cfg, fileData, displayClass }: QuartzComponentProps) { const text = fileData.text + if (text) { const segments: string[] = [] - const { text: timeTaken, words: _words } = readingTime(text) if (fileData.dates) { segments.push(formatDate(getDate(cfg, fileData)!)) } - segments.push(timeTaken) + // Display reading time if enabled + if (options.showReadingTime) { + const { text: timeTaken, words: _words } = readingTime(text) + segments.push(timeTaken) + } + return

{segments.join(", ")}

} else { return null From 4d338cec137a30fdc00771235f75d46fed878002 Mon Sep 17 00:00:00 2001 From: Aaron Pham <29749331+aarnphm@users.noreply.github.com> Date: Sun, 21 Jan 2024 14:33:32 -0500 Subject: [PATCH 03/14] feat(ofm): add options to parse arrows (#713) * feat(ofm): add options to parse arrows Signed-off-by: Aaron <29749331+aarnphm@users.noreply.github.com> * feat(ofm): add options to parse arrows Signed-off-by: Aaron <29749331+aarnphm@users.noreply.github.com> --------- Signed-off-by: Aaron <29749331+aarnphm@users.noreply.github.com> --- docs/features/Obsidian compatibility.md | 1 + quartz/plugins/transformers/ofm.ts | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/docs/features/Obsidian compatibility.md b/docs/features/Obsidian compatibility.md index d519e1779..1254370e0 100644 --- a/docs/features/Obsidian compatibility.md +++ b/docs/features/Obsidian compatibility.md @@ -25,6 +25,7 @@ Finally, Quartz also provides `Plugin.CrawlLinks` which allows you to customize - `callouts`: whether to enable [[callouts]]. Defaults to `true` - `mermaid`: whether to enable [[Mermaid diagrams]]. Defaults to `true` - `parseTags`: whether to try and parse tags in the content body. Defaults to `true` + - `parseArrows`: whether to try and parse arrows in the content body. Defaults to `true`. - `enableInHtmlEmbed`: whether to try and parse Obsidian flavoured markdown in raw HTML. Defaults to `false` - `enableYouTubeEmbed`: whether to enable embedded YouTube videos using external image Markdown syntax. Defaults to `false` - Link resolution behaviour: diff --git a/quartz/plugins/transformers/ofm.ts b/quartz/plugins/transformers/ofm.ts index 8c6f48890..e1f7651bd 100644 --- a/quartz/plugins/transformers/ofm.ts +++ b/quartz/plugins/transformers/ofm.ts @@ -23,6 +23,7 @@ export interface Options { callouts: boolean mermaid: boolean parseTags: boolean + parseArrows: boolean parseBlockReferences: boolean enableInHtmlEmbed: boolean enableYouTubeEmbed: boolean @@ -36,6 +37,7 @@ const defaultOptions: Options = { callouts: true, mermaid: true, parseTags: true, + parseArrows: true, parseBlockReferences: true, enableInHtmlEmbed: false, enableYouTubeEmbed: true, @@ -111,6 +113,8 @@ function canonicalizeCallout(calloutName: string): keyof typeof callouts { export const externalLinkRegex = /^https?:\/\//i +export const arrowRegex = new RegExp(/-{1,2}>/, "g") + // !? -> optional embedding // \[\[ -> open brace // ([^\[\]\|\#]+) -> one or more non-special characters ([,],|, or #) (name) @@ -294,6 +298,18 @@ export const ObsidianFlavoredMarkdown: QuartzTransformerPlugin ]) } + if (opts.parseArrows) { + replacements.push([ + arrowRegex, + (_value: string, ..._capture: string[]) => { + return { + type: "html", + value: ``, + } + }, + ]) + } + if (opts.parseTags) { replacements.push([ tagRegex, From 015b4f6a15da3b81f9e3ad004aa24636ab3882ed Mon Sep 17 00:00:00 2001 From: Jacky Zhao Date: Sun, 21 Jan 2024 12:39:15 -0800 Subject: [PATCH 04/14] fix: remove quartz 3 references, update font style in popovers --- README.md | 2 -- docs/index.md | 3 --- quartz/components/styles/popover.scss | 1 + 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/README.md b/README.md index 4b4731c9b..27d6dbdb0 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,6 @@ Quartz is a set of tools that helps you publish your [digital garden](https://jzhao.xyz/posts/networked-thought) and notes as a website for free. Quartz v4 features a from-the-ground rewrite focusing on end-user extensibility and ease-of-use. -**If you are looking for Quartz v3, you can find it on the [`hugo` branch](https://github.com/jackyzha0/quartz/tree/hugo).** - 🔗 Read the documentation and get started: https://quartz.jzhao.xyz/ [Join the Discord Community](https://discord.gg/cRFFHYye7t) diff --git a/docs/index.md b/docs/index.md index 655f5c39b..7804ac6ba 100644 --- a/docs/index.md +++ b/docs/index.md @@ -25,9 +25,6 @@ This will guide you through initializing your Quartz with content. Once you've d 4. [[build|Build and preview]] Quartz 5. [[hosting|Host]] Quartz online -> [!info] -> Coming from Quartz 3? See the [[migrating from Quartz 3|migration guide]] for the differences between Quartz 3 and Quartz 4 and how to migrate. - ## 🔧 Features - [[Obsidian compatibility]], [[full-text search]], [[graph view]], note transclusion, [[wikilinks]], [[backlinks]], [[Latex]], [[syntax highlighting]], [[popover previews]], [[Docker Support]], and [many more](./features) right out of the box diff --git a/quartz/components/styles/popover.scss b/quartz/components/styles/popover.scss index fae0e121b..e46292a21 100644 --- a/quartz/components/styles/popover.scss +++ b/quartz/components/styles/popover.scss @@ -26,6 +26,7 @@ max-height: 20rem; padding: 0 1rem 1rem 1rem; font-weight: initial; + font-style: initial; line-height: normal; font-size: initial; font-family: var(--bodyFont); From 0403fa70aa24cd3c16fbd9caf434cdcd277f1a14 Mon Sep 17 00:00:00 2001 From: Aaron Pham <29749331+aarnphm@users.noreply.github.com> Date: Sun, 21 Jan 2024 23:50:00 -0500 Subject: [PATCH 05/14] fix(search): use anchor element (closes #698) (#717) * fix(search): use anchor element This addresses #698 to allow search title to include links for SPA Signed-off-by: Aaron <29749331+aarnphm@users.noreply.github.com> * fix: formatter Signed-off-by: Aaron <29749331+aarnphm@users.noreply.github.com> * chore: move itemTile to `a` Signed-off-by: Aaron <29749331+aarnphm@users.noreply.github.com> * chore: remove nested a title Signed-off-by: Aaron <29749331+aarnphm@users.noreply.github.com> * chore(search): remove spaNavigate since now searchResult is an `a` item Signed-off-by: Aaron <29749331+aarnphm@users.noreply.github.com> --------- Signed-off-by: Aaron <29749331+aarnphm@users.noreply.github.com> --- quartz/components/scripts/search.inline.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/quartz/components/scripts/search.inline.ts b/quartz/components/scripts/search.inline.ts index 11e1c0da8..ab76b5f4d 100644 --- a/quartz/components/scripts/search.inline.ts +++ b/quartz/components/scripts/search.inline.ts @@ -222,16 +222,16 @@ document.addEventListener("nav", async (e: unknown) => { const resultToHTML = ({ slug, title, content, tags }: Item) => { const htmlTags = tags.length > 0 ? `
    ${tags.join("")}
` : `` - const button = document.createElement("button") - button.classList.add("result-card") - button.id = slug - button.innerHTML = `

${title}

${htmlTags}

${content}

` - button.addEventListener("click", () => { - const targ = resolveRelative(currentSlug, slug) - window.spaNavigate(new URL(targ, window.location.toString())) + const itemTile = document.createElement("a") + itemTile.classList.add("result-card") + itemTile.id = slug + itemTile.href = new URL(resolveRelative(currentSlug, slug), location.toString()).toString() + itemTile.innerHTML = `

${title}

${htmlTags}

${content}

` + itemTile.addEventListener("click", (event) => { + if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey) return hideSearch() }) - return button + return itemTile } function displayResults(finalResults: Item[]) { From 273931d25c73932abe810c97ecb424a387ada065 Mon Sep 17 00:00:00 2001 From: Jacky Zhao Date: Sun, 21 Jan 2024 21:14:12 -0800 Subject: [PATCH 06/14] fix: breadcrumbs on non-folder pages --- quartz/components/Breadcrumbs.tsx | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/quartz/components/Breadcrumbs.tsx b/quartz/components/Breadcrumbs.tsx index 0497b6458..182d9d62c 100644 --- a/quartz/components/Breadcrumbs.tsx +++ b/quartz/components/Breadcrumbs.tsx @@ -69,9 +69,9 @@ export default ((opts?: Partial) => { for (const file of allFiles) { if (file.slug?.endsWith("index")) { const folderParts = file.slug?.split("/") - if (folderParts) { - // 2nd last to exclude the /index - const folderName = folderParts[folderParts?.length - 2] + // 2nd last to exclude the /index + const folderName = folderParts?.at(-2) + if (folderName) { folderIndex.set(folderName, file) } } @@ -104,13 +104,14 @@ export default ((opts?: Partial) => { } // Add current file to crumb (can directly use frontmatter title) - if (options.showCurrentPage && slugParts.at(-1) === "") { + if (options.showCurrentPage && slugParts.at(-1) !== "index") { crumbs.push({ displayName: fileData.frontmatter!.title, path: "", }) } } + return (