From 24348b24a94c5f9ca285642b751e6798b92eedd9 Mon Sep 17 00:00:00 2001
From: Jacky Zhao <j.zhao2k19@gmail.com>
Date: Tue, 20 Jun 2023 05:50:25 +0000
Subject: [PATCH] fix: parsing wikilinks that have codeblock anchors, scroll to anchor
---
quartz/components/scripts/graph.inline.ts | 26 +++++++-------------------
1 files changed, 7 insertions(+), 19 deletions(-)
diff --git a/quartz/components/scripts/graph.inline.ts b/quartz/components/scripts/graph.inline.ts
index 40665ca..4ff2dfe 100644
--- a/quartz/components/scripts/graph.inline.ts
+++ b/quartz/components/scripts/graph.inline.ts
@@ -1,5 +1,6 @@
import { ContentDetails } from "../../plugins/emitters/contentIndex"
import * as d3 from 'd3'
+import { registerEscapeHandler, relative, removeAllChildren } from "./util"
type NodeData = {
id: string,
@@ -12,20 +13,9 @@
target: string
}
-function relative(from: string, to: string) {
- const pieces = [location.protocol, '//', location.host, location.pathname]
- const url = pieces.join('').slice(0, -from.length) + to
- return url
-}
-
-function removeAllChildren(node: HTMLElement) {
- while (node.firstChild) {
- node.removeChild(node.firstChild)
- }
-}
-
async function renderGraph(container: string, slug: string) {
- const graph = document.getElementById(container)!
+ const graph = document.getElementById(container)
+ if (!graph) return
removeAllChildren(graph)
let {
@@ -115,7 +105,6 @@
// calculate radius
const color = (d: NodeData) => {
- // TODO: does this handle the index page
const isCurrent = d.id === slug
return isCurrent ? "var(--secondary)" : "var(--gray)"
}
@@ -265,16 +254,15 @@
const container = document.getElementById("global-graph-outer")
container?.classList.add("active")
- function hideGlobalGraph(this: HTMLElement, e: HTMLElementEventMap["click"]) {
- if (e.target !== this) return
+ function hideGlobalGraph() {
container?.classList.remove("active")
- const graph = document.getElementById("global-graph-container")!
+ const graph = document.getElementById("global-graph-container")
+ if (!graph) return
removeAllChildren(graph)
}
- container?.removeEventListener("click", hideGlobalGraph)
- container?.addEventListener("click", hideGlobalGraph)
+ registerEscapeHandler(container, hideGlobalGraph)
}
document.addEventListener("nav", async (e: unknown) => {
--
Gitblit v1.10.0