2022-12-07 15:55:45 +00:00
|
|
|
<script setup lang="ts">
|
2023-01-08 06:21:09 +00:00
|
|
|
import type { mastodon } from 'masto'
|
2022-12-07 15:55:45 +00:00
|
|
|
|
2022-12-09 21:13:59 +00:00
|
|
|
const props = defineProps<{
|
2023-01-08 06:21:09 +00:00
|
|
|
card: mastodon.v1.PreviewCard
|
2022-12-09 21:13:59 +00:00
|
|
|
/** For the preview image, only the small image mode is displayed */
|
|
|
|
smallPictureOnly?: boolean
|
|
|
|
/** When it is root card in the list, not appear as a child card */
|
|
|
|
root?: boolean
|
2022-12-07 15:55:45 +00:00
|
|
|
}>()
|
2022-12-13 18:30:40 +00:00
|
|
|
|
|
|
|
// mastodon's default max og image width
|
|
|
|
const ogImageWidth = 400
|
|
|
|
|
2022-12-09 21:13:59 +00:00
|
|
|
const alt = $computed(() => `${props.card.title} - ${props.card.title}`)
|
2022-12-13 18:30:40 +00:00
|
|
|
const isSquare = $computed(() => (
|
|
|
|
props.smallPictureOnly
|
|
|
|
|| props.card.width === props.card.height
|
|
|
|
|| Number(props.card.width || 0) < ogImageWidth
|
|
|
|
|| Number(props.card.height || 0) < ogImageWidth / 2
|
|
|
|
))
|
2022-12-11 10:52:36 +00:00
|
|
|
const providerName = $computed(() => props.card.providerName ? props.card.providerName : new URL(props.card.url).hostname)
|
2022-12-07 15:55:45 +00:00
|
|
|
|
2023-01-06 17:39:37 +00:00
|
|
|
const gitHubCards = $(useFeatureFlag('experimentalGitHubCards'))
|
2022-12-19 15:52:32 +00:00
|
|
|
|
2022-12-07 15:55:45 +00:00
|
|
|
// TODO: handle card.type: 'photo' | 'video' | 'rich';
|
2023-01-08 06:21:09 +00:00
|
|
|
const cardTypeIconMap: Record<mastodon.v1.PreviewCardType, string> = {
|
2022-12-19 15:52:32 +00:00
|
|
|
link: 'i-ri:profile-line',
|
|
|
|
photo: 'i-ri:image-line',
|
|
|
|
video: 'i-ri:play-line',
|
|
|
|
rich: 'i-ri:profile-line',
|
|
|
|
}
|
2022-12-07 15:55:45 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
2022-12-18 13:22:28 +00:00
|
|
|
<StatusPreviewGitHub v-if="gitHubCards && providerName === 'GitHub'" :card="card" />
|
2022-12-09 21:13:59 +00:00
|
|
|
<NuxtLink
|
2022-12-18 13:22:28 +00:00
|
|
|
v-else
|
2022-12-09 21:13:59 +00:00
|
|
|
block
|
|
|
|
of-hidden
|
|
|
|
:to="card.url"
|
2023-01-10 09:05:59 +00:00
|
|
|
bg-card
|
|
|
|
hover:bg-active
|
2022-12-09 21:13:59 +00:00
|
|
|
:class="{
|
|
|
|
'flex': isSquare,
|
|
|
|
'p-4': root,
|
2023-01-10 09:05:59 +00:00
|
|
|
'rounded-lg': !root,
|
2022-12-09 21:13:59 +00:00
|
|
|
}"
|
|
|
|
target="_blank"
|
2023-01-09 13:22:19 +00:00
|
|
|
external
|
2022-12-07 15:55:45 +00:00
|
|
|
>
|
2022-12-09 21:13:59 +00:00
|
|
|
<div
|
2022-12-18 13:22:28 +00:00
|
|
|
v-if="card.image"
|
2022-12-09 21:13:59 +00:00
|
|
|
flex flex-col
|
|
|
|
display-block of-hidden
|
|
|
|
:class="{
|
2023-01-11 19:08:15 +00:00
|
|
|
'sm:(min-w-32 w-32 h-32) min-w-24 w-24 h-24': isSquare,
|
2023-01-10 09:05:59 +00:00
|
|
|
'w-full aspect-[1.91]': !isSquare,
|
2022-12-09 21:13:59 +00:00
|
|
|
'rounded-lg': root,
|
|
|
|
}"
|
|
|
|
>
|
2022-12-07 15:55:45 +00:00
|
|
|
<CommonBlurhash
|
|
|
|
:blurhash="card.blurhash"
|
|
|
|
:src="card.image"
|
|
|
|
:width="card.width"
|
|
|
|
:height="card.height"
|
|
|
|
:alt="alt"
|
2022-12-09 21:13:59 +00:00
|
|
|
w-full h-full object-cover
|
2022-12-07 15:55:45 +00:00
|
|
|
/>
|
2022-12-09 21:13:59 +00:00
|
|
|
</div>
|
2022-12-11 10:52:36 +00:00
|
|
|
<div
|
|
|
|
v-else
|
2023-01-11 19:08:15 +00:00
|
|
|
min-w-24 w-24 h-24 sm="min-w-32 w-32 h-32" bg="slate-500/10" flex justify-center items-center
|
2022-12-11 10:52:36 +00:00
|
|
|
:class="[
|
|
|
|
root ? 'rounded-lg' : '',
|
|
|
|
]"
|
|
|
|
>
|
2022-12-19 15:52:32 +00:00
|
|
|
<div :class="cardTypeIconMap[card.type]" w="30%" h="30%" text-secondary />
|
2022-12-09 21:13:59 +00:00
|
|
|
</div>
|
2023-01-11 19:08:15 +00:00
|
|
|
<StatusPreviewCardInfo :p="isSquare ? 'x-4' : '4'" :root="root" :card="card" :provider="providerName" />
|
2022-12-09 21:13:59 +00:00
|
|
|
</NuxtLink>
|
2022-12-07 15:55:45 +00:00
|
|
|
</template>
|