e96bfee317
- SearchField-Atom (src/lib/ui/SearchField.svelte, light/dark) in Kalender, Beiträge und globaler Suche einheitlich eingesetzt - Featured-Hero (neuester Beitrag groß, Seite 1 ungefiltert, nur bei "newest") - Neu-Badge in PostCard (Beitrag < 7 Tage) - Org-/BI-Tags (tag-org-*) in eigene Sektion; Tags ohne Beiträge ausgeblendet - Inline-Newsletter-CTA, prominenter RSS-Link - Sortierung Neueste/Älteste (Server-Param + URL-State, Toggle neben Pagination, Pagination trägt sort weiter) - Pagination als Pills (rounded-full) - Kalender: Tag-Filter einklappbar, Filterleiste mit Suche + Heute Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
89 lines
3.0 KiB
Svelte
89 lines
3.0 KiB
Svelte
<script lang="ts">
|
|
import '$lib/iconify-offline';
|
|
import Icon from "@iconify/svelte";
|
|
import { useTranslate } from "$lib/translations";
|
|
import { T } from "$lib/translations";
|
|
|
|
const t = useTranslate();
|
|
|
|
let {
|
|
currentPage = 1,
|
|
totalPages = 1,
|
|
basePath = "/posts",
|
|
activeTag = null,
|
|
sort = "newest",
|
|
}: {
|
|
currentPage: number;
|
|
totalPages: number;
|
|
basePath?: string;
|
|
activeTag?: string | null;
|
|
sort?: "newest" | "oldest";
|
|
} = $props();
|
|
|
|
const query = $derived(sort === "oldest" ? "?sort=oldest" : "");
|
|
|
|
function tagHref(tagSlug: string | null): string {
|
|
if (!tagSlug) return `${basePath}/${query}`;
|
|
return `${basePath}/tag/${encodeURIComponent(tagSlug)}/${query}`;
|
|
}
|
|
|
|
function pageHref(page: number): string {
|
|
if (page <= 1) return tagHref(activeTag ?? null);
|
|
const tagPart = activeTag
|
|
? `/tag/${encodeURIComponent(activeTag)}`
|
|
: "";
|
|
return `${basePath}${tagPart}/page/${page}/${query}`;
|
|
}
|
|
|
|
const showPagination = $derived(totalPages > 1);
|
|
const hasPrev = $derived(currentPage > 1);
|
|
const hasNext = $derived(currentPage < totalPages);
|
|
const prevPage = $derived(currentPage - 1);
|
|
const nextPage = $derived(currentPage + 1);
|
|
|
|
const pageNumbers = $derived.by(() => {
|
|
const max = 5;
|
|
let start = Math.max(1, currentPage - Math.floor(max / 2));
|
|
const end = Math.min(totalPages, start + max - 1);
|
|
if (end - start + 1 < max) start = Math.max(1, end - max + 1);
|
|
return Array.from({ length: end - start + 1 }, (_, i) => start + i);
|
|
});
|
|
|
|
const baseShape =
|
|
"rounded-full h-8 mx-[3px] flex justify-center items-center no-underline text-xs font-medium border transition-colors";
|
|
const inactiveColors =
|
|
"text-stein-700 border-stein-200 bg-white hover:bg-stein-50 hover:border-wald-300";
|
|
const activeColors =
|
|
"text-white border-wald-500 bg-wald-500 hover:bg-wald-600 hover:border-wald-600 pointer-events-none";
|
|
const numberShape = "min-w-8 px-2";
|
|
const navShape = "px-3 gap-1";
|
|
</script>
|
|
|
|
{#if showPagination}
|
|
<nav class="inline-flex py-4 items-center" aria-label="Seitennavigation">
|
|
<div class="flex items-center">
|
|
{#if hasPrev}
|
|
<a href={pageHref(prevPage)} class="{baseShape} {navShape} {inactiveColors}" aria-label={t(T.pagination_prev)}>
|
|
<Icon icon="lucide:chevron-left" class="size-4" aria-hidden="true" />
|
|
<span class="hidden sm:inline">{t(T.pagination_prev)}</span>
|
|
</a>
|
|
{/if}
|
|
{#each pageNumbers as num}
|
|
<a
|
|
href={pageHref(num)}
|
|
class="{baseShape} {numberShape} {num === currentPage ? activeColors : inactiveColors}"
|
|
aria-current={num === currentPage ? 'page' : undefined}
|
|
>
|
|
{num}
|
|
</a>
|
|
{/each}
|
|
{#if hasNext}
|
|
<a href={pageHref(nextPage)} class="{baseShape} {navShape} {inactiveColors}" aria-label={t(T.pagination_next)}>
|
|
<span class="hidden sm:inline">{t(T.pagination_next)}</span>
|
|
<Icon icon="lucide:chevron-right" class="size-4" aria-hidden="true" />
|
|
</a>
|
|
{/if}
|
|
</div>
|
|
</nav>
|
|
{/if}
|