Something went wrong. Try again.
An all-affirming social network based on the AT Protocol. nagi.suibari.com
Something went wrong. Try again.
1.2 kB · 34 lines
Svelte
at main
1234567891011121314151617181920212223242526272829303132333435<script lang="ts"> import type { LinkCardView } from '$lib/api/types'; import { APPVIEW_URL } from '$lib/api/appview'; import { httpUrl } from '$lib/atproto/facets'; import { decorateSiblingUrl } from '$lib/sso/links'; let { card }: { card: LinkCardView } = $props(); // カードの URI が http(s) の場合のみリンクにする。細工された javascript: URI は // クリック不能なプレーンカードとして描画する。 // 姉妹アプリ宛なら did ヒントを足す(それ以外の URL は素通り)。 let safeHref = $derived(decorateSiblingUrl(httpUrl(card.uri))); let host = $derived.by(() => { try { return new URL(card.uri).hostname; } catch { return card.uri; } }); const resolve = (url: string) => (url.startsWith('/') ? APPVIEW_URL + url : url);</script>
<svelte:element this={safeHref ? 'a' : 'div'} class="link-card" href={safeHref} target={safeHref ? '_blank' : undefined} rel={safeHref ? 'noopener noreferrer' : undefined}> {#if card.thumb}<img src={resolve(card.thumb)} alt="" />{/if} <span class="link-card-copy"> <strong>{card.title}</strong> {#if card.description}<span>{card.description}</span>{/if} <small>{host}</small> </span></svelte:element>