118 lines
3.2 KiB
Svelte
118 lines
3.2 KiB
Svelte
<script lang="ts">
|
|
import { parseURL } from '$comp/input/Link.svelte'
|
|
import type { View } from '$lib/settings.svelte'
|
|
import { Material } from 'mono-svelte'
|
|
import { optimizeImageURL } from '../helpers'
|
|
import { Icon, Link } from 'svelte-hero-icons'
|
|
|
|
interface Props {
|
|
url: string
|
|
thumbnail_url?: string
|
|
nsfw?: boolean
|
|
embed_title?: string
|
|
view?: View
|
|
}
|
|
|
|
let {
|
|
url,
|
|
thumbnail_url,
|
|
nsfw = false,
|
|
embed_title,
|
|
view = 'cozy',
|
|
}: Props = $props()
|
|
|
|
let richURL = $derived(parseURL(url))
|
|
</script>
|
|
|
|
<!--
|
|
@component
|
|
For embed-type posts. Displays embed card or a compact link.
|
|
-->
|
|
{#if embed_title && view == 'cozy'}
|
|
<Material
|
|
color="uniform"
|
|
class={[
|
|
'flex flex-col-reverse sm:flex-row overflow-hidden gap-4 z-0 relative',
|
|
'dark:bg-zinc-950 hover:bg-slate-50 hover:dark:bg-zinc-900 transition-colors',
|
|
'group/link',
|
|
]}
|
|
rounding="2xl"
|
|
element="a"
|
|
padding="sm"
|
|
href={url}
|
|
target="_blank"
|
|
rel="noopener"
|
|
>
|
|
{#if thumbnail_url}
|
|
<img
|
|
src={optimizeImageURL(thumbnail_url, 32)}
|
|
alt=""
|
|
class="-z-10 absolute w-full object-cover h-full opacity-5 brightness-150
|
|
dark:brightness-70 dark:opacity-10 blur-2xl -inset-px"
|
|
/>
|
|
{/if}
|
|
<div class={['flex flex-col gap-1 p-2', thumbnail_url && '-mt-2 sm:mt-0']}>
|
|
{#if richURL}
|
|
<div
|
|
class="text-slate-600 dark:text-zinc-400 inline-flex items-center gap-1 text-xs font-medium"
|
|
>
|
|
{richURL.hostname}
|
|
</div>
|
|
{/if}
|
|
<p class="font-medium text-base">{embed_title}</p>
|
|
</div>
|
|
{#if thumbnail_url}
|
|
<picture class="mb-auto sm:ml-auto shrink-0 sm:w-1/3 sm:max-w-60">
|
|
{#each ['webp'] as format}
|
|
<source
|
|
srcset="{optimizeImageURL(
|
|
thumbnail_url,
|
|
256,
|
|
format as 'avif' | 'webp',
|
|
)} 256w, {optimizeImageURL(
|
|
thumbnail_url,
|
|
512,
|
|
format as 'avif' | 'webp',
|
|
)} 512w"
|
|
media="(min-width: 0px)"
|
|
type="image/{format}"
|
|
/>
|
|
{/each}
|
|
<img
|
|
src={optimizeImageURL(thumbnail_url, -1)}
|
|
class="object-cover w-full sm:max-w-96 h-32 sm:min-h-16 bg-slate-200 dark:bg-zinc-800 rounded-xl"
|
|
width={600}
|
|
height={400}
|
|
alt=""
|
|
class:blur-3xl={nsfw}
|
|
/>
|
|
</picture>
|
|
{/if}
|
|
</Material>
|
|
{:else}
|
|
<a
|
|
href={url}
|
|
target="_blank"
|
|
rel="noopener noreferrer"
|
|
class="flex flex-row text-slate-900 dark:text-zinc-400 items-center overflow-hidden group/link hover:underline space-x-1 my-1"
|
|
>
|
|
<Icon src={Link} size="16" micro class="shrink-0" />
|
|
{#if richURL}
|
|
<div
|
|
class="flex max-w-full overflow-hidden font-medium self-start justify-self-start w-max text-sm"
|
|
>
|
|
{richURL.hostname}
|
|
{#if richURL.pathname != '/'}
|
|
<span
|
|
class="text-slate-500 dark:text-zinc-500 whitespace-nowrap font-normal group-hover/link:opacity-100 opacity-0 transition-opacity duration-100"
|
|
>
|
|
{richURL.pathname}
|
|
</span>
|
|
{/if}
|
|
</div>
|
|
{:else}
|
|
{url}
|
|
{/if}
|
|
</a>
|
|
{/if}
|