-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
const query = urlParams.get("q")?.toLowerCase().trim();
const title = post.getAttribute("data-title")?.toLowerCase() || "";
const description = post.getAttribute("data-description")?.toLowerCase() || "";
const matchesQuery = query
? title.includes(query) || description.includes(query) || tags.includes(query)
: true;
const searchInput = document.getElementById("search-input");
if (searchInput && query) {
searchInput.value = query;
}
// Optional: search form handling
document.getElementById("search-form")?.addEventListener("submit", e => {
e.preventDefault();
const value = searchInput?.value.trim();
const newUrl = new URL(location.href);
if (value) newUrl.searchParams.set("q", value);
else newUrl.searchParams.delete("q");
if (tag) newUrl.searchParams.set("tag", tag);
window.location.href = newUrl.toString();
});<form id="search-form" class="mb-6 flex gap-2">
<input
type="text"
id="search-input"
name="q"
class="w-full px-4 py-2 border rounded-md"
placeholder="Search blog posts..."
/>
<button type="submit" class="px-4 py-2 bg-gray-800 text-white rounded-md">Search</button>
</form>Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels