diff --git a/src/components/BlogOverview.svelte b/src/components/BlogOverview.svelte index fb59cfb..13e35fa 100644 --- a/src/components/BlogOverview.svelte +++ b/src/components/BlogOverview.svelte @@ -54,18 +54,40 @@ } = $props(); let query = $state(""); + let year = $state(""); const normalizedQuery = $derived(query.trim().toLowerCase()); - const isSearching = $derived(normalizedQuery.length >= 2); + const isFiltering = $derived(normalizedQuery.length >= 2 || year !== ""); - const searchResults = $derived.by(() => { - if (!isSearching || !searchIndex) return []; + function yearOf(entry: SearchIndexEntry): string { + const iso = entry.created ?? ""; + if (!iso) return ""; + const d = new Date(iso); + return Number.isNaN(d.getTime()) ? "" : String(d.getFullYear()); + } + + const availableYears = $derived.by(() => { + if (!searchIndex) return []; + const set = new Set(); + for (const p of searchIndex) { + const y = yearOf(p); + if (y) set.add(y); + } + return Array.from(set).sort((a, b) => b.localeCompare(a)); + }); + + const filteredResults = $derived.by(() => { + if (!isFiltering || !searchIndex) return []; const q = normalizedQuery; return searchIndex .filter((p) => { - const hay = `${p.headline} ${p.excerpt} ${p.subheadline} ${p.tags.join(" ")}`.toLowerCase(); - return hay.includes(q); + if (year && yearOf(p) !== year) return false; + if (q) { + const hay = `${p.headline} ${p.excerpt} ${p.subheadline} ${p.tags.join(" ")}`.toLowerCase(); + if (!hay.includes(q)) return false; + } + return true; }) - .slice(0, 40); + .slice(0, 80); }); function searchResultHref(slug: string): string { @@ -95,7 +117,7 @@
{#if searchIndex} -
+
+ {#if availableYears.length > 0} + + {/if}
{/if} - {#if !isSearching && upcomingEvents.length > 0} + {#if !isFiltering && upcomingEvents.length > 0}

@@ -142,13 +184,23 @@

{/if} - {#if isSearching} -
- {searchResults.length} Treffer für „{query}" + {#if isFiltering} +
+ + {filteredResults.length} + {filteredResults.length === 1 ? "Treffer" : "Treffer"} + {#if query}für „{query}"{/if} + {#if year}im Jahr {year}{/if} + +
- {#if searchResults.length > 0} + {#if filteredResults.length > 0}
- {#each searchResults as hit} + {#each filteredResults as hit} {#if hit.image}