From fb8e42f632448c90248a9a1b5bb1f6300b725aa7 Mon Sep 17 00:00:00 2001 From: spaghet Date: Thu, 12 Nov 2026 22:38:58 -0500 Subject: [PATCH] refactor: consolidate blog and project filtering into shared component The /blog and /projects listings previously used byte-identical copies of the same filtering island, which meant bugs like inconsistent AND-vs-OR tag semantics, duplicate-case tags, and a missing empty state were duplicated across both. This commit introduces `FilteredList`, a single shared Solid component that: - Unifies tag, keyword, and sort filtering for both collections - Seeds initial filter state from the SSR request URL to avoid hydration mismatches - Syncs active filters into the address bar via `history.replaceState` so filtered views survive refreshes and can be shared - Restores filters on browser back/forward navigation (`popstate`) - Case-folds and dedupes tags when parsing URL params Filter logic (collectTags, filterEntries, sortKeys, URL param encoding) is extracted into `src/lib/filters.ts` with full unit test coverage. --- src/components/Blog.tsx | 74 ----- src/components/FilteredList.tsx | 210 ++++++++++++++ src/components/Projects.tsx | 68 ----- src/components/__tests__/list-islands.test.ts | 170 ++++++++---- src/lib/__tests__/content.test.ts | 34 +-- src/lib/__tests__/filters.test.ts | 257 ++++++++++++++++++ src/lib/content.ts | 20 -- src/lib/filters.ts | 184 +++++++++++++ src/lib/types.ts | 24 +- src/pages/blog/index.astro | 18 +- src/pages/projects/index.astro | 18 +- 11 files changed, 811 insertions(+), 266 deletions(-) delete mode 100644 src/components/Blog.tsx create mode 100644 src/components/FilteredList.tsx delete mode 100644 src/components/Projects.tsx create mode 100644 src/lib/__tests__/filters.test.ts create mode 100644 src/lib/filters.ts diff --git a/src/components/Blog.tsx b/src/components/Blog.tsx deleted file mode 100644 index 43e8874..0000000 --- a/src/components/Blog.tsx +++ /dev/null @@ -1,74 +0,0 @@ -import type { BlogPost } from "@lib/types" -import { createMemo, createSignal, For } from "solid-js" -import ArrowCard from "@components/ArrowCard" -import { cn } from "@lib/utils" -import { filterByTags } from "@lib/content" - -type Props = { - tags: string[] - data: BlogPost[] -} - -export default function Blog({ data, tags }: Props) { - const [filter, setFilter] = createSignal(new Set()) - - // `createMemo`, not `createEffect` + a signal: effects never run during SSR, so the - // signal stayed at its initial `[]` and the server emitted "SHOWING 0 OF 3" with an - // empty