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.
This commit is contained in:
1 parent
9e157a4fa3
commit
fb8e42f632
11 files changed
+811
-266
No files matched your search
@@ -23,26 +23,6 @@ export function byDateDesc(a: DatedEntry, b: DatedEntry): number {
|
||||
return diff !== 0 ? diff : a.id.localeCompare(b.id)
|
||||
}
|
||||
|
||||
/**
|
||||
* Tag filter shared by the Blog and Projects islands (their logic was
|
||||
* byte-identical duplicates of each other).
|
||||
*
|
||||
* AND semantics: an entry must carry *every* selected tag, so adding a second
|
||||
* tag narrows the result set rather than unioning it. Case-insensitive on both
|
||||
* sides. Lives here (not in the islands) because the memo now runs during SSR,
|
||||
* so a throw on a malformed entry would be a 500 rather than an empty list —
|
||||
* and because this is the behavior worth asserting directly.
|
||||
*/
|
||||
export function filterByTags<T extends { tags: string[] }>(
|
||||
entries: T[],
|
||||
selected: Iterable<string>
|
||||
): T[] {
|
||||
const wanted = Array.from(selected, (value) => String(value).toLowerCase())
|
||||
return entries.filter((entry) =>
|
||||
wanted.every((tag) => entry.tags.some((entryTag) => entryTag.toLowerCase() === tag))
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Map a blog or project content entry down to the slim, serializable shape
|
||||
* used by ArrowCard and the search index. Centralising this keeps every page
|
||||
|
||||
Reference in new issue
Block a user