swyxio / swyxkit

An opinionated blog starter for SvelteKit + Tailwind + Netlify. Refreshed for SvelteKit 1.0!
https://swyxkit.netlify.app/
MIT License
668 stars 87 forks source link

Filter by Category results in "No blogposts found!" #196

Open Laidlaw opened 1 year ago

Laidlaw commented 1 year ago

Seen here: https://swyxkit.netlify.app/blog?show=Essay

I think filtering by category worked before the fuzzySearch integration. Could the culprit be here? blog/+page.svelte 49-72

let loaded = false;
    const filterCategories = async (_items, _, s) => {
        if (!$selectedCategories?.length) return _items;
        return _items
            .filter((item) => {
                return $selectedCategories
                    .map((element) => {
                        return element.toLowerCase();
                    })
                    .includes(item.category.toLowerCase());
            })
            .filter((item) => item.toString().toLowerCase().includes(s));
    };
    $: searchFn = filterCategories;
    function loadsearchFn() {
        if (loaded) return;
        import('./fuzzySearch').then((fuzzy) => {
            searchFn = fuzzy.fuzzySearch;
            loaded = true;
        });
    }
    if ($search) loadsearchFn()
    /** @type import('$lib/types').ContentItem[]  */
    let list;
    $: searchFn(items, $selectedCategories, $search).then(_items => list = _items);
swyxio commented 1 year ago

yeah theres something in the logic to figure out here, i agree this is a bug. PR welcome! i doubt i will get to this in timely fashion