From e482fa10970fd6a0c1c0ec836db84ba4187bc8f7 Mon Sep 17 00:00:00 2001
From: Jacky Zhao <j.zhao2k19@gmail.com>
Date: Thu, 06 Apr 2023 22:06:01 +0000
Subject: [PATCH] fix: graph and tooltip sometimes not showing

---
 assets/js/util.js |   13 +++++++++----
 1 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/assets/js/util.js b/assets/js/util.js
index 3346b7d..bd434c7 100644
--- a/assets/js/util.js
+++ b/assets/js/util.js
@@ -40,8 +40,8 @@
       .replace(/^\s{0,3}>\s?/g, "")
       .replace(/(^|\n)\s{0,3}>\s?/g, "\n\n")
       .replace(/^\s{1,2}\[(.*?)\]: (\S+)( ".*?")?\s*$/g, "")
-      .replace(/([\*_]{1,3})(\S.*?\S{0,1})\1/g, "$2")
-      .replace(/([\*_]{1,3})(\S.*?\S{0,1})\1/g, "$2")
+      .replace(/([\*_]{1,3})(\S.*?\S?)\1/g, "$2")
+      .replace(/([\*_]{1,3})(\S.*?\S?)\1/g, "$2")
       .replace(/(`{3,})(.*?)\1/gm, "$2")
       .replace(/`(.+?)`/g, "$1")
       .replace(/\n{2,}/g, "\n\n")
@@ -65,7 +65,7 @@
       .split(" ")
       .slice(0, h)
     return (
-      (before.length == h ? `...${before.join(" ")}` : before.join(" ")) +
+      (before.length === h ? `...${before.join(" ")}` : before.join(" ")) +
       `<span class="search-highlight">${term}</span>` +
       after.join(" ")
     )
@@ -117,12 +117,17 @@
 const redir = (id, term) => {
   const shouldTrim = PRODUCTION && SEARCH_ENABLED
   const baseURLPrefix = shouldTrim ? "" : BASE_URL.replace(/\/$/g, "")
-  const urlString = `${baseURLPrefix}${id}#:~:text=${encodeURIComponent(term)}/`
+  const urlString = `${baseURLPrefix}${id}#:~:text=${encodeURIComponent(term)}`
   window.Million.navigate(
     new URL(urlString),
     ".singlePage",
   )
   closeSearch()
+  plausible("Search", {
+    props: {
+      term
+    }
+  })
 }
 
 function openSearch() {

--
Gitblit v1.10.0