aboutsummaryrefslogtreecommitdiff
path: root/static/js/fixedsearch.ts
diff options
context:
space:
mode:
Diffstat (limited to 'static/js/fixedsearch.ts')
-rw-r--r--static/js/fixedsearch.ts30
1 files changed, 19 insertions, 11 deletions
diff --git a/static/js/fixedsearch.ts b/static/js/fixedsearch.ts
index fafe5ee..63a3b4b 100644
--- a/static/js/fixedsearch.ts
+++ b/static/js/fixedsearch.ts
@@ -1,10 +1,10 @@
+/*
+ Modified Version of Fixed Search: https://gist.github.com/cmod/5410eae147e4318164258742dd053993
+ MIT License: https://gist.github.com/Arty2/8b0c43581013753438a3d35c15091a9f#file-license-md
+*/
+
(function () {
self.addEventListener("DOMContentLoaded", function () {
- /*
- Originally Based on fixedsearch, a super fast, client side search for Hugo.io with Fusejs.io
- based on https://gist.github.com/cmod/5410eae147e4318164258742dd053993
- */
-
const form = document.getElementById("search-form"); // search form
const query = document.getElementById("search-input"); // input box for search
const submit = document.getElementById("search-submit"); // form submit button
@@ -167,6 +167,12 @@
}
}
+ function escape(text) {
+ const escaped = document.createElement("textarea");
+ escaped.textContent = text;
+ return escaped.innerHTML;
+ }
+
function search(term, data, options) {
const results = fuzzysort.go(term, data, options);
let items = "";
@@ -175,10 +181,12 @@
let separator = "—";
if (term.length === 0) separator = "";
items = `
- <li>
- <a href="javascript: void(0)" tabindex="0">${term} ${separator} No Results Found</a>
- </li>
- `;
+ <li>
+ <a href="javascript: void(0)" tabindex="0">${
+ escape(term)
+ } ${separator} No Results Found</a>
+ </li>
+ `;
dropdown.removeAttribute("hidden");
container.setAttribute("data-focus", "");
} else {
@@ -186,7 +194,7 @@
for (const string in results.slice(0, 10)) {
const title = results[string].obj.title;
let highlight = fuzzysort.highlight(
- fuzzysort.single(term, title),
+ fuzzysort.single(escape(term), escape(title)),
"<span>",
"</span>",
);
@@ -200,7 +208,7 @@
<li>
<a href="${results[string].obj.url}" tabindex="0">${highlight}</a>
</li>
- `;
+ `;
}
}