flotilla/src/app/components/ContentLinkInline.svelte

32 lines
1.1 KiB
Svelte
Raw Normal View History

2024-09-24 21:12:38 +00:00
<script lang="ts">
import {displayUrl} from "@welshman/lib"
2025-02-04 03:28:29 +00:00
import {preventDefault} from "@lib/html"
2025-09-10 22:26:39 +00:00
import LinkRound from "@assets/icons/link-round.svg?dataurl"
2024-09-24 21:12:38 +00:00
import Icon from "@lib/components/Icon.svelte"
import Link from "@lib/components/Link.svelte"
import ContentLinkDetail from "@app/components/ContentLinkDetail.svelte"
import {pushModal} from "@app/util/modal"
2025-11-26 01:06:21 +00:00
import {PLATFORM_URL} from "@app/core/state"
2024-09-24 21:12:38 +00:00
const {value} = $props()
2024-09-24 21:12:38 +00:00
const url = value.url.toString()
2025-11-26 01:06:21 +00:00
const external = !url.startsWith(PLATFORM_URL)
const href = external ? url : url.replace(PLATFORM_URL, "")
const expand = () => pushModal(ContentLinkDetail, {url}, {fullscreen: true})
2024-09-24 21:12:38 +00:00
</script>
{#if url.match(/\.(jpe?g|png|gif|webp)$/)}
2024-11-18 20:51:13 +00:00
<!-- Use a real link so people can copy the href -->
2025-02-04 00:37:14 +00:00
<a href={url} class="link-content whitespace-nowrap" onclick={preventDefault(expand)}>
2025-09-10 22:26:39 +00:00
<Icon icon={LinkRound} size={3} class="inline-block" />
{displayUrl(url)}
2024-11-18 20:51:13 +00:00
</a>
{:else}
2025-11-26 01:06:21 +00:00
<Link {external} {href} class="link-content whitespace-nowrap">
2025-09-10 22:26:39 +00:00
<Icon icon={LinkRound} size={3} class="inline-block" />
{displayUrl(url)}
</Link>
{/if}