diff --git a/package-lock.json b/package-lock.json
index d8b01818..772be5d3 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "coryd.dev",
- "version": "1.5.14",
+ "version": "1.5.13",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "coryd.dev",
- "version": "1.5.14",
+ "version": "1.5.13",
"license": "MIT",
"dependencies": {
"@cdransf/api-text": "^1.5.0",
diff --git a/package.json b/package.json
index dec2a137..0c2fc6d1 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "coryd.dev",
- "version": "1.5.14",
+ "version": "1.5.13",
"description": "The source for my personal site. Built using 11ty (and other tools).",
"type": "module",
"engines": {
diff --git a/src/assets/scripts/index.js b/src/assets/scripts/index.js
index b778f512..fa5e1886 100644
--- a/src/assets/scripts/index.js
+++ b/src/assets/scripts/index.js
@@ -106,41 +106,58 @@ window.addEventListener("load", () => {
"tags",
"total_plays",
],
+ searchOptions: {
+ fields: ["title", "tags"],
+ prefix: true,
+ fuzzy: 0.1,
+ boost: { title: 3, tags: 1.5 },
+ },
});
-
+ const $form = document.querySelector(".search__form");
const $input = document.querySelector(".search__form--input");
+ const $fallback = document.querySelector(".search__form--fallback");
const $typeCheckboxes = document.querySelectorAll(
'.search__form--type input[type="checkbox"]'
);
const $results = document.querySelector(".search__results");
const $loadMoreButton = document.querySelector(".search__load-more");
+ $form.removeAttribute("action");
+ $form.removeAttribute("method");
+ if ($fallback) $fallback.remove();
+
const PAGE_SIZE = 10;
let currentPage = 1;
let currentResults = [];
let total = 0;
+ let resultsById = {};
let debounceTimeout;
- const getSearchResults = (query) => {
- return miniSearch.search(query, {
- fields: ["title", "tags"],
- prefix: true,
- fuzzy: 0.1,
- boost: { title: 4, tags: 2 },
- });
+ const parseMarkdown = (markdown) => {
+ if (!markdown) return "";
+ return markdown
+ .replace(/\*\*(.*?)\*\*/g, "$1")
+ .replace(/\*(.*?)\*/g, "$1")
+ .replace(/\[(.*?)\]\((.*?)\)/g, '$1')
+ .replace(/\n/g, "
")
+ .replace(/[#*_~`]/g, "");
};
- const updateSearchResults = (results) => {
- if (currentPage === 1) {
- renderSearchResults(results);
- } else {
- appendSearchResults(results);
- }
-
- const moreResultsToShow = currentPage * PAGE_SIZE < total;
- $loadMoreButton.style.display = moreResultsToShow ? "block" : "none";
+ const truncateDescription = (markdown, maxLength = 150) => {
+ const htmlDescription = parseMarkdown(markdown);
+ const tempDiv = document.createElement("div");
+ tempDiv.innerHTML = htmlDescription;
+ const plainText = tempDiv.textContent || tempDiv.innerText || "";
+ return plainText.length > maxLength
+ ? `${plainText.substring(0, maxLength)}...`
+ : plainText;
};
+ const formatArtistTitle = (title, totalPlays) =>
+ totalPlays > 0
+ ? `${title} ${totalPlays} plays`
+ : title;
+
const renderSearchResults = (results) => {
if (results.length > 0) {
const resultHTML = results
@@ -148,14 +165,17 @@ window.addEventListener("load", () => {
const truncatedDesc = truncateDescription(description);
const formattedTitle =
type === "artist" && total_plays !== undefined
- ? `${title} ${total_plays} plays`
+ ? formatArtistTitle(title, total_plays)
: title;
return `
-
${truncatedDesc}
-${truncatedDesc}
+${truncatedDesc}
-${truncatedDesc}
+