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.
42 lines
1.4 KiB
Plaintext
42 lines
1.4 KiB
Plaintext
---
|
|
import { getCollection } from "astro:content"
|
|
import PageLayout from "@layouts/PageLayout.astro"
|
|
import TopLayout from "@layouts/TopLayout.astro"
|
|
import BottomLayout from "@layouts/BottomLayout.astro"
|
|
import FilteredList from "@components/FilteredList"
|
|
import { BLOG } from "@consts"
|
|
import { byDateDesc } from "@lib/content"
|
|
import { parseFilterParams } from "@lib/filters"
|
|
|
|
const entries = await getCollection("blog", ({ data }) => !data.draft)
|
|
// Only the fields the cards and the filters read. `content` was serialized into
|
|
// the island's props on every request and never matched against — the markdown
|
|
// body is the single largest thing on this page.
|
|
const posts = entries
|
|
.sort(byDateDesc)
|
|
.map((entry) => ({
|
|
id: entry.id,
|
|
title: entry.data.title,
|
|
summary: entry.data.summary,
|
|
date: entry.data.date.toISOString(),
|
|
tags: entry.data.tags,
|
|
}))
|
|
|
|
// Frontmatter runs on the server, so the initial filter state has to come from
|
|
// the request URL rather than `window.location` (see src/pages/search/index.astro).
|
|
const initial = parseFilterParams(Astro.url.searchParams)
|
|
---
|
|
|
|
<PageLayout title={BLOG.TITLE} description={BLOG.DESCRIPTION}>
|
|
<TopLayout>
|
|
<div class="animate page-heading">
|
|
{BLOG.TITLE}
|
|
</div>
|
|
</TopLayout>
|
|
<BottomLayout>
|
|
<div class="animate">
|
|
<FilteredList client:load collection="blog" entries={posts} initial={initial} />
|
|
</div>
|
|
</BottomLayout>
|
|
</PageLayout>
|