From 77485b754dbb3d08e437b4157f3eafb5871624b9 Mon Sep 17 00:00:00 2001 From: Aiden Bai Date: Tue, 3 May 2022 08:47:42 -0700 Subject: [PATCH 01/15] Fix popover --- assets/js/popover.js | 40 +++++++++++++-------------- assets/js/router.js | 25 +++++++++++++++++ layouts/_default/section.html | 1 - layouts/_default/single.html | 3 +-- layouts/_default/taxonomy.html | 1 - layouts/_default/term.html | 1 - layouts/index.html | 4 +-- layouts/partials/head.html | 49 +++++++++++++++------------------- layouts/partials/popover.html | 7 ----- 9 files changed, 67 insertions(+), 64 deletions(-) create mode 100644 assets/js/router.js delete mode 100644 layouts/partials/popover.html diff --git a/assets/js/popover.js b/assets/js/popover.js index ee0477efd..460c245f7 100644 --- a/assets/js/popover.js +++ b/assets/js/popover.js @@ -1,5 +1,5 @@ function htmlToElement(html) { - const template = document.createElement('template') + const template = document.createElement("template") html = html.trim() template.innerHTML = html return template.content.firstChild @@ -7,29 +7,27 @@ function htmlToElement(html) { function initPopover(baseURL) { const basePath = baseURL.replace(window.location.origin, "") - document.addEventListener("DOMContentLoaded", () => { - fetchData.then(({ content }) => { - const links = [...document.getElementsByClassName("internal-link")] - links - .filter(li => li.dataset.src) - .forEach(li => { - const linkDest = content[li.dataset.src.replace(/\/$/g, "").replace(basePath, "")] - if (linkDest) { - const popoverElement = `
+ fetchData.then(({ content }) => { + const links = [...document.getElementsByClassName("internal-link")] + links + .filter((li) => li.dataset.src) + .forEach((li) => { + const linkDest = content[li.dataset.src.replace(/\/$/g, "").replace(basePath, "")] + if (linkDest) { + const popoverElement = `

${linkDest.title}

${removeMarkdown(linkDest.content).split(" ", 20).join(" ")}...

${new Date(linkDest.lastmodified).toLocaleDateString()}

` - const el = htmlToElement(popoverElement) - li.appendChild(el) - li.addEventListener("mouseover", () => { - el.classList.add("visible") - }) - li.addEventListener("mouseout", () => { - el.classList.remove("visible") - }) - } - }) - }) + const el = htmlToElement(popoverElement) + li.appendChild(el) + li.addEventListener("mouseover", () => { + el.classList.add("visible") + }) + li.addEventListener("mouseout", () => { + el.classList.remove("visible") + }) + } + }) }) } diff --git a/assets/js/router.js b/assets/js/router.js new file mode 100644 index 000000000..5c874eee6 --- /dev/null +++ b/assets/js/router.js @@ -0,0 +1,25 @@ +import { router, navigate } from "https://unpkg.com/million/dist/router.mjs" + +export const init = (loader) => { + // SPA navigation for access later + window.navigate = navigate + // We only mutate document.title and content within .singlePage element + router(".singlePage") + // We need on initial load, then subsequent redirs + window.addEventListener("million:navigate", () => callback(loader)) + window.addEventListener("DOMContentLoaded", () => callback(loader)) +} + +export const callback = (loader) => { + // requestAnimationFrame() delays graph draw until SPA routing is finished + const draw = () => { + const container = document.getElementById("graph-container") + // retry if the graph is not ready + if (!container) return requestAnimationFrame(draw) + // clear the graph in case there is anything within it + container.textContent = "" + + loader() + } + requestAnimationFrame(draw) +} diff --git a/layouts/_default/section.html b/layouts/_default/section.html index 1a4aae058..abdf0b05c 100644 --- a/layouts/_default/section.html +++ b/layouts/_default/section.html @@ -19,7 +19,6 @@ {{partial "contact.html" .}}
-{{partial "popover.html" .}} diff --git a/layouts/_default/single.html b/layouts/_default/single.html index 88a859c3b..91eda290b 100644 --- a/layouts/_default/single.html +++ b/layouts/_default/single.html @@ -22,11 +22,10 @@
  • {{ .LinkTitle | humanize }}
  • {{ end }} - {{partial "toc.html" .}} + {{partial "toc.html" .}} {{partial "textprocessing.html" . }} {{partial "footer.html" .}} - {{partial "popover.html" .}} diff --git a/layouts/_default/taxonomy.html b/layouts/_default/taxonomy.html index b7a45b10f..e0a1e876c 100644 --- a/layouts/_default/taxonomy.html +++ b/layouts/_default/taxonomy.html @@ -28,7 +28,6 @@ {{partial "contact.html" .}} -{{partial "popover.html" .}} diff --git a/layouts/_default/term.html b/layouts/_default/term.html index 16ea85cf8..58f024bcc 100644 --- a/layouts/_default/term.html +++ b/layouts/_default/term.html @@ -19,7 +19,6 @@ {{partial "contact.html" .}} -{{partial "popover.html" .}} diff --git a/layouts/index.html b/layouts/index.html index ee33d7cc8..224c99784 100644 --- a/layouts/index.html +++ b/layouts/index.html @@ -13,12 +13,10 @@ {{partial "darkmode.html" .}}
    - {{partial "toc.html" .}} + {{partial "toc.html" .}} {{partial "textprocessing.html" . }}
    {{partial "footer.html" .}} - {{partial "popover.html" .}} - diff --git a/layouts/partials/head.html b/layouts/partials/head.html index 37938a556..60ff78272 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -35,6 +35,10 @@ {{partial "katex.html" .}} + {{ $popover := resources.Get "js/popover.js" | resources.Fingerprint "md5" | + resources.Minify }} + + {{$linkIndex := resources.Get "indices/linkIndex.json" | resources.Fingerprint "md5" | resources.Minify | }} {{$contentIndex := resources.Get @@ -59,36 +63,25 @@ })) {{if $.Site.Data.config.enableSPA}} + {{ $router := resources.Get "js/router.js" | resources.Fingerprint "md5" | + resources.Minify }} {{else}} diff --git a/layouts/partials/popover.html b/layouts/partials/popover.html deleted file mode 100644 index 1d1662282..000000000 --- a/layouts/partials/popover.html +++ /dev/null @@ -1,7 +0,0 @@ -{{if $.Site.Data.config.enableLinkPreview}} -{{ $js := resources.Get "js/popover.js" | resources.Fingerprint "md5" | resources.Minify }} - - -{{end}} \ No newline at end of file From 9c71f07355d8e98478e755875e53596f66c58fa9 Mon Sep 17 00:00:00 2001 From: Aiden Bai Date: Tue, 3 May 2022 08:48:35 -0700 Subject: [PATCH 02/15] Enable config for testing --- data/config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data/config.yaml b/data/config.yaml index afa531c36..2676ac2ac 100644 --- a/data/config.yaml +++ b/data/config.yaml @@ -3,7 +3,7 @@ enableToc: true openToc: false enableLinkPreview: true enableLatex: true -enableSPA: false +enableSPA: true description: Host your second brain and digital garden for free. Quartz features extremely fast full-text search, Wikilink support, backlinks, local graph, tags, and link previews. From 9d3bbd607687899d173e9087f2782d7460ebee82 Mon Sep 17 00:00:00 2001 From: Aiden Bai Date: Tue, 3 May 2022 08:53:18 -0700 Subject: [PATCH 03/15] Fix active node on graph --- assets/js/graph.js | 4 ++-- data/config.yaml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/assets/js/graph.js b/assets/js/graph.js index c5829e927..c32035d83 100644 --- a/assets/js/graph.js +++ b/assets/js/graph.js @@ -1,5 +1,5 @@ async function drawGraph( - url, + _url, baseUrl, pathColors, depth, @@ -10,7 +10,7 @@ async function drawGraph( const container = document.getElementById('graph-container') const { index, links, content } = await fetchData - const curPage = url.replace(baseUrl, '') + const curPage = window.location.href.replace(baseUrl, '').slice(0, -1) const parseIdsFromLinks = (links) => [ ...new Set(links.flatMap((link) => [link.source, link.target])), diff --git a/data/config.yaml b/data/config.yaml index afa531c36..2676ac2ac 100644 --- a/data/config.yaml +++ b/data/config.yaml @@ -3,7 +3,7 @@ enableToc: true openToc: false enableLinkPreview: true enableLatex: true -enableSPA: false +enableSPA: true description: Host your second brain and digital garden for free. Quartz features extremely fast full-text search, Wikilink support, backlinks, local graph, tags, and link previews. From 4cca3c1f2df91ba7bb111346447279087e04069a Mon Sep 17 00:00:00 2001 From: Aiden Bai Date: Tue, 3 May 2022 09:04:15 -0700 Subject: [PATCH 04/15] Peg router version --- assets/js/router.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/js/router.js b/assets/js/router.js index 5c874eee6..bf7e3c859 100644 --- a/assets/js/router.js +++ b/assets/js/router.js @@ -1,4 +1,4 @@ -import { router, navigate } from "https://unpkg.com/million/dist/router.mjs" +import { router, navigate } from "https://unpkg.com/million@1.8.9-0/dist/router.mjs" export const init = (loader) => { // SPA navigation for access later From 3c660dd9b5f9e1133bc8a1228287508504b7c132 Mon Sep 17 00:00:00 2001 From: Aiden Bai Date: Tue, 3 May 2022 09:20:01 -0700 Subject: [PATCH 05/15] Remove unnecessary 'url' param in drawGraph --- assets/js/graph.js | 1 - layouts/partials/head.html | 1 - 2 files changed, 2 deletions(-) diff --git a/assets/js/graph.js b/assets/js/graph.js index c32035d83..e92f7db62 100644 --- a/assets/js/graph.js +++ b/assets/js/graph.js @@ -1,5 +1,4 @@ async function drawGraph( - _url, baseUrl, pathColors, depth, diff --git a/layouts/partials/head.html b/layouts/partials/head.html index 37938a556..93051cb98 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -75,7 +75,6 @@ container.textContent = ""; drawGraph( - {{strings.TrimRight "/" .Page.Permalink}}, {{strings.TrimRight "/" .Site.BaseURL}}, {{$.Site.Data.graphConfig.paths}}, {{$.Site.Data.graphConfig.depth}}, From 32c79a561fa82dbf6537b96e83ab3da2a848b211 Mon Sep 17 00:00:00 2001 From: Aiden Bai Date: Tue, 3 May 2022 09:21:44 -0700 Subject: [PATCH 06/15] Remove unnecessary 'url' argument in graph.html --- layouts/partials/graph.html | 1 - 1 file changed, 1 deletion(-) diff --git a/layouts/partials/graph.html b/layouts/partials/graph.html index b8b2f6162..6bc77b648 100644 --- a/layouts/partials/graph.html +++ b/layouts/partials/graph.html @@ -18,7 +18,6 @@ {{else}} From 1a5d158fce648492c48644acfea039261ac1dffa Mon Sep 17 00:00:00 2001 From: Aiden Bai Date: Tue, 3 May 2022 10:38:41 -0700 Subject: [PATCH 11/15] Support active node with other data at end of url --- assets/js/graph.js | 3 ++- assets/js/search.js | 2 +- layouts/partials/graph.html | 10 ---------- 3 files changed, 3 insertions(+), 12 deletions(-) diff --git a/assets/js/graph.js b/assets/js/graph.js index db1cfe2a5..5739acdca 100644 --- a/assets/js/graph.js +++ b/assets/js/graph.js @@ -9,7 +9,8 @@ async function drawGraph( const container = document.getElementById('graph-container') const { index, links, content } = await fetchData - const curPage = window.location.href.replace(baseUrl, "").replace(/\/$/g, "") + // Use .pathname to remove hashes / searchParams / text fragments + const curPage = window.location.pathname.replace(/\/$/g, "") const parseIdsFromLinks = (links) => [ ...new Set(links.flatMap((link) => [link.source, link.target])), diff --git a/assets/js/search.js b/assets/js/search.js index f124d5829..26ea39adc 100644 --- a/assets/js/search.js +++ b/assets/js/search.js @@ -144,7 +144,7 @@ const removeMarkdown = ( // SPA navigation window.navigate( new URL( - `${BASE_URL}${id}#:~:text=${encodeURIComponent(term)}/` + `${BASE_URL.replace(/\/$/g, "")}${id}#:~:text=${encodeURIComponent(term)}/` ), '.singlePage' ) diff --git a/layouts/partials/graph.html b/layouts/partials/graph.html index 6bc77b648..b9f79763c 100644 --- a/layouts/partials/graph.html +++ b/layouts/partials/graph.html @@ -16,13 +16,3 @@ {{ $js := resources.Get "js/graph.js" | resources.Fingerprint "md5" }} - From aaed5dc1f1849a54869743596a6133548e83392d Mon Sep 17 00:00:00 2001 From: Aiden Bai Date: Tue, 3 May 2022 10:54:39 -0700 Subject: [PATCH 12/15] Support /path root sites --- assets/js/graph.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/assets/js/graph.js b/assets/js/graph.js index 5739acdca..e1bbbebed 100644 --- a/assets/js/graph.js +++ b/assets/js/graph.js @@ -7,10 +7,13 @@ async function drawGraph( enableZoom ) { const container = document.getElementById('graph-container') - const { index, links, content } = await fetchData + + const rawUrl = new URL(window.location.href); // Use .pathname to remove hashes / searchParams / text fragments - const curPage = window.location.pathname.replace(/\/$/g, "") + const cleanUrl = rawUrl.origin + rawUrl.pathname + + const curPage = cleanUrl.replace(/\/$/g, "").replace(baseUrl, "") const parseIdsFromLinks = (links) => [ ...new Set(links.flatMap((link) => [link.source, link.target])), From 2b5c03c97286e06e94e8a27634678e64473a2ec8 Mon Sep 17 00:00:00 2001 From: Aiden Bai Date: Tue, 3 May 2022 10:55:45 -0700 Subject: [PATCH 13/15] Remove redundant URL construction --- assets/js/graph.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/assets/js/graph.js b/assets/js/graph.js index e1bbbebed..f71e44d37 100644 --- a/assets/js/graph.js +++ b/assets/js/graph.js @@ -9,9 +9,8 @@ async function drawGraph( const container = document.getElementById('graph-container') const { index, links, content } = await fetchData - const rawUrl = new URL(window.location.href); // Use .pathname to remove hashes / searchParams / text fragments - const cleanUrl = rawUrl.origin + rawUrl.pathname + const cleanUrl = window.location.origin + window.location.pathname const curPage = cleanUrl.replace(/\/$/g, "").replace(baseUrl, "") From b4ff12ca0b1b5179c20a1ea57f182caa703b0826 Mon Sep 17 00:00:00 2001 From: Aiden Bai Date: Wed, 4 May 2022 08:10:59 -0700 Subject: [PATCH 14/15] Fix latex --- .pnpm-debug.log | 14 ++++++++++++++ layouts/partials/head.html | 9 +++++++++ layouts/partials/katex.html | 11 ----------- 3 files changed, 23 insertions(+), 11 deletions(-) create mode 100644 .pnpm-debug.log diff --git a/.pnpm-debug.log b/.pnpm-debug.log new file mode 100644 index 000000000..ce5adc898 --- /dev/null +++ b/.pnpm-debug.log @@ -0,0 +1,14 @@ +{ + "0 debug pnpm:scope": { + "selected": 1 + }, + "1 error pnpm": { + "code": "ERR_PNPM_NO_SCRIPT", + "err": { + "name": "pnpm", + "message": "Missing script: dev", + "code": "ERR_PNPM_NO_SCRIPT", + "stack": "pnpm: Missing script: dev\n at Object.handler (/opt/homebrew/lib/node_modules/pnpm/dist/pnpm.cjs:170956:15)\n at async /opt/homebrew/lib/node_modules/pnpm/dist/pnpm.cjs:175391:21\n at async run (/opt/homebrew/lib/node_modules/pnpm/dist/pnpm.cjs:175365:34)\n at async runPnpm (/opt/homebrew/lib/node_modules/pnpm/dist/pnpm.cjs:175583:5)\n at async /opt/homebrew/lib/node_modules/pnpm/dist/pnpm.cjs:175575:7" + } + } +} \ No newline at end of file diff --git a/layouts/partials/head.html b/layouts/partials/head.html index b917afbc4..097cae79c 100644 --- a/layouts/partials/head.html +++ b/layouts/partials/head.html @@ -87,6 +87,15 @@ {{if $.Site.Data.config.enableLinkPreview}} initPopover({{strings.TrimRight "/" .Site.BaseURL }}) {{end}} + {{if $.Site.Data.config.enableLatex}} + renderMathInElement(document.body, { + delimiters: [ + {left: '$$', right: '$$', display: true}, + {left: '$', right: '$', display: false}, + ], + throwOnError : false + }); + {{end}} }; attachSPARouting(draw); diff --git a/layouts/partials/katex.html b/layouts/partials/katex.html index e11c4f14e..756ef779e 100644 --- a/layouts/partials/katex.html +++ b/layouts/partials/katex.html @@ -2,15 +2,4 @@ - {{end}} From 7b3696b877c33f8dc605be1f4f4a688fe0df5b84 Mon Sep 17 00:00:00 2001 From: Aiden Bai Date: Wed, 4 May 2022 08:39:25 -0700 Subject: [PATCH 15/15] Remove pnpm debug log --- .pnpm-debug.log | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 .pnpm-debug.log diff --git a/.pnpm-debug.log b/.pnpm-debug.log deleted file mode 100644 index ce5adc898..000000000 --- a/.pnpm-debug.log +++ /dev/null @@ -1,14 +0,0 @@ -{ - "0 debug pnpm:scope": { - "selected": 1 - }, - "1 error pnpm": { - "code": "ERR_PNPM_NO_SCRIPT", - "err": { - "name": "pnpm", - "message": "Missing script: dev", - "code": "ERR_PNPM_NO_SCRIPT", - "stack": "pnpm: Missing script: dev\n at Object.handler (/opt/homebrew/lib/node_modules/pnpm/dist/pnpm.cjs:170956:15)\n at async /opt/homebrew/lib/node_modules/pnpm/dist/pnpm.cjs:175391:21\n at async run (/opt/homebrew/lib/node_modules/pnpm/dist/pnpm.cjs:175365:34)\n at async runPnpm (/opt/homebrew/lib/node_modules/pnpm/dist/pnpm.cjs:175583:5)\n at async /opt/homebrew/lib/node_modules/pnpm/dist/pnpm.cjs:175575:7" - } - } -} \ No newline at end of file