From 88cc6646196c9f7e8493929f30102a471f6655e4 Mon Sep 17 00:00:00 2001 From: Michael DeMarco Date: Tue, 4 Jul 2023 17:20:51 -0700 Subject: [PATCH] fix: url bug; remove production check --- assets/js/util.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/assets/js/util.js b/assets/js/util.js index a7a0769c4d832..fc32f598a5bf7 100644 --- a/assets/js/util.js +++ b/assets/js/util.js @@ -102,9 +102,8 @@ const highlight = (content, term) => { }) .join(" ") .replaceAll(' ', " "); - return `${startIndex === 0 ? "" : "..."}${mappedText}${ - endIndex === splitText.length ? "" : "..." - }`; + return `${startIndex === 0 ? "" : "..."}${mappedText}${endIndex === splitText.length ? "" : "..." + }`; }; // Common utilities for search @@ -116,8 +115,9 @@ const resultToHTML = ({ url, title, content }) => { }; const redir = (id, term) => { - const shouldTrim = PRODUCTION && SEARCH_ENABLED; - const baseURLPrefix = shouldTrim ? "" : BASE_URL.replace(/\/$/g, ""); + // Remove the trailing slash from the base URL; `id` is already prefixed with a slash + const baseURLPrefix = BASE_URL.replace(/\/$/g, ""); + const urlString = `${baseURLPrefix}${id}#:~:text=${encodeURIComponent(term)}`; window.Million.navigate(new URL(urlString), ".singlePage"); closeSearch(); @@ -216,6 +216,7 @@ const displayResults = (term, finalResults, extractHighlight = false) => { } const anchors = [...document.getElementsByClassName("result-card")]; + anchors.forEach((anchor) => { anchor.onclick = () => redir(anchor.id, term); });