From 65a3c155ceb9ea9353a8c6a9c1c89039b39d7084 Mon Sep 17 00:00:00 2001 From: Dominic Ferrando Date: Mon, 21 Apr 2025 00:00:50 -0400 Subject: [PATCH] Add catalog search --- web/static/index.js | 18 ++++++++++++++++++ web/views/board.templ | 5 ++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/web/static/index.js b/web/static/index.js index 18688ab..7cdb15a 100644 --- a/web/static/index.js +++ b/web/static/index.js @@ -72,3 +72,21 @@ function resizeCatalogPreviewImgs() { } } } + +function applyCatalogSearch() { + const searchText = $("catalogSearch").value.toLowerCase(); + + const posts = Array.from(document.querySelectorAll(".catalog-preview")); + for (const post of posts) { + const headerContent = post.querySelector("h1 a").textContent; + const bodyContent = post.querySelector("p").textContent; + + const contentToSearch = (headerContent + "\n" + bodyContent).toLowerCase(); + if (contentToSearch.search(searchText) === -1) { + post.style.display = "none"; + } + else { + post.style.display = ""; + } + } +} diff --git a/web/views/board.templ b/web/views/board.templ index 9a9f2bc..4559b0f 100644 --- a/web/views/board.templ +++ b/web/views/board.templ @@ -75,12 +75,15 @@ templ Board(board database.Board) { +
} }