From 22998871c984b2b6000e6933d2bd339315bba8ff Mon Sep 17 00:00:00 2001 From: dprevoznik <58714078+dprevoznik@users.noreply.github.com> Date: Thu, 1 Oct 2026 21:16:06 +0000 Subject: [PATCH] Fix cookbook search to filter every card The search only matched cards linking to kernel/cookbooks on GitHub, so cards pointing to guides or partner sites never hid. Filter all cards in the page content instead, and hide a section and its heading when none of its cards match. Co-Authored-By: Claude Opus 5.5 --- snippets/cookbook-search.jsx | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/snippets/cookbook-search.jsx b/snippets/cookbook-search.jsx index eb00f2fa..0223ccaa 100644 --- a/snippets/cookbook-search.jsx +++ b/snippets/cookbook-search.jsx @@ -3,22 +3,21 @@ const { useState, useCallback } = React; export const CookbookSearch = () => { const [matches, setMatches] = useState(null); - const getCards = () => { - const anchors = Array.from( - document.querySelectorAll('a[href^="https://github.com/kernel/cookbooks/tree/main/"]') - ).filter((a) => !a.closest('nav') && !a.closest('aside')); - const cards = anchors.map((a) => a.closest('.card') || a); - return Array.from(new Set(cards)); - }; - const handleInput = useCallback((e) => { const q = e.target.value.trim().toLowerCase(); - const cards = getCards(); let count = 0; - cards.forEach((card) => { - const hit = q === '' || card.textContent.toLowerCase().includes(q); - card.style.display = hit ? '' : 'none'; - if (hit) count++; + document.querySelectorAll('#content .columns').forEach((section) => { + let sectionCount = 0; + section.querySelectorAll('.card').forEach((card) => { + const hit = q === '' || card.textContent.toLowerCase().includes(q); + card.style.display = hit ? '' : 'none'; + if (hit) sectionCount++; + }); + const display = sectionCount > 0 ? '' : 'none'; + section.style.display = display; + const heading = section.previousElementSibling; + if (heading && heading.tagName === 'H2') heading.style.display = display; + count += sectionCount; }); setMatches(q === '' ? null : count); }, []);