Refactor components and add tests for improved functionality and coverage

This commit is contained in:
spaghet committed 2026-11-04 22:16:17 -05:00
1 parent bbb76eaa31
commit ab6cd7c162
13 files changed
+253 -54

No files matched your search

+20
View File
@@ -23,6 +23,26 @@ 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