From 1a5d158fce648492c48644acfea039261ac1dffa Mon Sep 17 00:00:00 2001 From: Aiden Bai Date: Tue, 3 May 2022 10:38:41 -0700 Subject: [PATCH 1/3] 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 db1cfe2..5739acd 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 f124d58..26ea39a 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 6bc77b6..b9f7976 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 2/3] 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 5739acd..e1bbbeb 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 3/3] 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 e1bbbeb..f71e44d 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, "")