Skip to content

Commit

Permalink
fix: url bug; remove production check
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelfromyeg committed Jul 5, 2023
1 parent 07bc5d7 commit 88cc664
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions assets/js/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,8 @@ const highlight = (content, term) => {
})
.join(" ")
.replaceAll('</span> <span class="search-highlight">', " ");
return `${startIndex === 0 ? "" : "..."}${mappedText}${
endIndex === splitText.length ? "" : "..."
}`;
return `${startIndex === 0 ? "" : "..."}${mappedText}${endIndex === splitText.length ? "" : "..."
}`;
};

// Common utilities for search
Expand All @@ -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();
Expand Down Expand Up @@ -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);
});
Expand Down

0 comments on commit 88cc664

Please sign in to comment.