2024-09-24 21:12:38 +00:00
|
|
|
<script lang="ts">
|
2025-12-03 01:09:56 +00:00
|
|
|
import {call, displayUrl} from "@welshman/lib"
|
2026-02-13 23:37:17 +00:00
|
|
|
import {isRelayUrl, getTagValue} from "@welshman/util"
|
2026-01-12 18:12:47 +00:00
|
|
|
import {preventDefault, stopPropagation} 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"
|
2024-10-18 00:10:11 +00:00
|
|
|
import ContentLinkDetail from "@app/components/ContentLinkDetail.svelte"
|
2025-08-21 22:01:31 +00:00
|
|
|
import {pushModal} from "@app/util/modal"
|
2026-02-13 23:37:17 +00:00
|
|
|
import {PLATFORM_URL, IMAGE_CONTENT_TYPES} from "@app/core/state"
|
2025-12-03 01:09:56 +00:00
|
|
|
import {makeSpacePath} from "@app/util/routes"
|
2024-09-24 21:12:38 +00:00
|
|
|
|
2026-01-12 18:12:47 +00:00
|
|
|
const {value, event} = $props()
|
2024-09-24 21:12:38 +00:00
|
|
|
|
|
|
|
|
const url = value.url.toString()
|
2026-02-13 23:37:17 +00:00
|
|
|
const fileType = getTagValue("file-type", event.tags) || ""
|
2025-12-03 01:09:56 +00:00
|
|
|
const [href, external] = call(() => {
|
|
|
|
|
if (isRelayUrl(url)) return [makeSpacePath(url), false]
|
|
|
|
|
if (url.startsWith(PLATFORM_URL)) return [url.replace(PLATFORM_URL, ""), false]
|
|
|
|
|
|
|
|
|
|
return [url, true]
|
|
|
|
|
})
|
2024-10-18 00:10:11 +00:00
|
|
|
|
2026-01-12 18:12:47 +00:00
|
|
|
const expand = () => pushModal(ContentLinkDetail, {value, event}, {fullscreen: true})
|
2024-09-24 21:12:38 +00:00
|
|
|
</script>
|
|
|
|
|
|
2026-02-13 23:37:17 +00:00
|
|
|
{#if url.match(/\.(jpe?g|png|gif|webp)$/) || IMAGE_CONTENT_TYPES.includes(fileType)}
|
2024-11-18 20:51:13 +00:00
|
|
|
<!-- Use a real link so people can copy the href -->
|
2026-01-13 21:16:57 +00:00
|
|
|
<a
|
|
|
|
|
href={url}
|
|
|
|
|
class="link-content whitespace-nowrap"
|
|
|
|
|
onclick={stopPropagation(preventDefault(expand))}>
|
2025-09-10 22:26:39 +00:00
|
|
|
<Icon icon={LinkRound} size={3} class="inline-block" />
|
2024-10-18 00:10:11 +00:00
|
|
|
{displayUrl(url)}
|
2024-11-18 20:51:13 +00:00
|
|
|
</a>
|
2024-10-18 00:10:11 +00:00
|
|
|
{: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" />
|
2024-10-18 00:10:11 +00:00
|
|
|
{displayUrl(url)}
|
|
|
|
|
</Link>
|
|
|
|
|
{/if}
|