// Library page — combines saved links and annotations from Cameron's PDS. import { getProfile, getSembleData, type SembleCard, } from "../data.ts"; import { AnnotationList, listAnnotations } from "./library-annotations.tsx"; import { PageNav } from "./page-nav.tsx"; function displayDomain(url: string): string { try { return new URL(url).hostname.replace(/^www\./, ""); } catch { return url; } } function cardTitle(card: SembleCard): string { const metadataTitle = card.cardContent?.title; if (metadataTitle && metadataTitle !== "Bluesky") return metadataTitle; try { const url = new URL(card.url); if (url.hostname === "bsky.app" && url.pathname.includes("/profile/")) { const profile = url.pathname.split("/").filter(Boolean).at(-1); if (profile) return `@${profile}`; } } catch { // Fall through to the stored title or domain. } return metadataTitle || displayDomain(card.url); } function formattedDate(date: string): string { return new Date(date).toLocaleDateString("en-US", { month: "short", day: "numeric", year: "numeric", }); } function recordUrl(uri?: string): string | undefined { return uri ? `https://pdsls.dev/${uri}` : undefined; } function cleanDescription(description?: string): string | undefined { return description?.replace(/\s+/g, " ").trim(); } export async function Library({ embedded = false }: { embedded?: boolean } = {}) { const [{ collections, cards, available }, annotations, profile] = await Promise.all([ getSembleData(100), listAnnotations(), getProfile(), ]); const urlCards = cards.filter((card) => card.type === "URL"); const looseCount = urlCards.filter((card) => card.collections.length === 0).length; return (
{!embedded && }
{!embedded &&

Library

Links and passages I wanted to keep. Collections gather related material; annotations stay attached to the thing that provoked them.

Saved links
{String(urlCards.length).padStart(2, "0")}
Collections
{String(collections.length).padStart(2, "0")}
Annotations
{String(annotations.length).padStart(2, "0")}
} {!available ? (

Catalogue unavailable

The records are still there.

This page could not reach the PDS just now. It is an upstream read failure, not an empty collection.

) : ( )}

Annotations

{annotations.length} passages and notes made with{" "} Margin .

{annotations.length === 0 ? (

No annotations yet.

) : ( )}
); }