2022-12-18 06:11:39 +09:00
|
|
|
<script setup lang="ts">
|
2023-01-08 15:21:09 +09:00
|
|
|
import type { mastodon } from 'masto'
|
2023-02-02 04:14:23 +09:00
|
|
|
import reservedNames from 'github-reserved-names'
|
2022-12-18 06:11:39 +09:00
|
|
|
|
|
|
|
const props = defineProps<{
|
2023-01-08 15:21:09 +09:00
|
|
|
card: mastodon.v1.PreviewCard
|
2022-12-18 06:11:39 +09:00
|
|
|
}>()
|
|
|
|
|
|
|
|
type UrlType = 'user' | 'repo' | 'issue' | 'pull'
|
|
|
|
interface Meta {
|
|
|
|
type: UrlType
|
2022-12-19 21:29:16 +09:00
|
|
|
user?: string
|
2022-12-18 22:22:28 +09:00
|
|
|
titleUrl: string
|
2022-12-18 06:11:39 +09:00
|
|
|
avatar: string
|
|
|
|
details: string
|
|
|
|
repo?: string
|
|
|
|
number?: string
|
2022-12-21 04:42:28 +09:00
|
|
|
author?: {
|
|
|
|
avatar: string
|
|
|
|
user: string
|
2022-12-18 06:11:39 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-02 04:14:23 +09:00
|
|
|
// Supported paths
|
|
|
|
// /user
|
|
|
|
// /user/repo
|
|
|
|
// /user/repo/issues/number
|
|
|
|
// /user/repo/pull/number
|
|
|
|
// /sponsors/user
|
|
|
|
const supportedReservedRoutes = ['sponsors']
|
2023-01-04 00:59:49 +09:00
|
|
|
|
2024-02-22 00:20:08 +09:00
|
|
|
const meta = computed(() => {
|
2022-12-18 06:11:39 +09:00
|
|
|
const { url } = props.card
|
|
|
|
const path = url.split('https://github.com/')[1]
|
2023-02-02 04:14:23 +09:00
|
|
|
const [firstName, secondName] = path?.split('/') || []
|
|
|
|
if (!firstName || (reservedNames.check(firstName) && !supportedReservedRoutes.includes(firstName)))
|
|
|
|
return undefined
|
2022-12-23 18:08:13 +09:00
|
|
|
|
2023-02-02 04:14:23 +09:00
|
|
|
const firstIsUser = firstName && !supportedReservedRoutes.includes(firstName)
|
2022-12-23 18:08:13 +09:00
|
|
|
const user = firstIsUser ? firstName : secondName
|
|
|
|
const repo = firstIsUser ? secondName : undefined
|
|
|
|
|
2022-12-18 06:11:39 +09:00
|
|
|
let type: UrlType = repo ? 'repo' : 'user'
|
2022-12-23 18:08:13 +09:00
|
|
|
let number: string | undefined
|
|
|
|
let details = (props.card.title ?? '').replace('GitHub - ', '').split(' · ')[0]
|
|
|
|
|
|
|
|
if (repo) {
|
|
|
|
const repoPath = `${user}/${repo}`
|
|
|
|
details = details.replace(`${repoPath}: `, '')
|
|
|
|
const inRepoPath = path.split(`${repoPath}/`)?.[1]
|
|
|
|
if (inRepoPath) {
|
|
|
|
number = inRepoPath.match(/issues\/(\d+)/)?.[1]
|
|
|
|
if (number) {
|
|
|
|
type = 'issue'
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
number = inRepoPath.match(/pull\/(\d+)/)?.[1]
|
|
|
|
if (number)
|
|
|
|
type = 'pull'
|
|
|
|
}
|
2022-12-18 06:11:39 +09:00
|
|
|
}
|
|
|
|
}
|
2022-12-23 18:08:13 +09:00
|
|
|
|
2022-12-21 04:42:28 +09:00
|
|
|
const avatar = `https://github.com/${user}.png?size=256`
|
|
|
|
|
|
|
|
const author = props.card.authorName
|
2024-02-25 01:46:14 +09:00
|
|
|
return {
|
2022-12-18 06:11:39 +09:00
|
|
|
type,
|
|
|
|
user,
|
2022-12-18 22:22:28 +09:00
|
|
|
titleUrl: `https://github.com/${user}${repo ? `/${repo}` : ''}`,
|
2022-12-18 06:11:39 +09:00
|
|
|
details,
|
|
|
|
repo,
|
|
|
|
number,
|
|
|
|
avatar,
|
2022-12-21 04:42:28 +09:00
|
|
|
author: author
|
|
|
|
? {
|
|
|
|
avatar: `https://github.com/${author}.png?size=64`,
|
|
|
|
user: author,
|
|
|
|
}
|
|
|
|
: undefined,
|
2024-02-25 01:46:14 +09:00
|
|
|
} satisfies Meta
|
2022-12-18 06:11:39 +09:00
|
|
|
})
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div
|
2023-02-02 04:14:23 +09:00
|
|
|
v-if="card.image && meta"
|
2022-12-18 06:11:39 +09:00
|
|
|
flex flex-col
|
|
|
|
display-block of-hidden
|
2023-01-10 18:05:59 +09:00
|
|
|
bg-card
|
2022-12-18 06:11:39 +09:00
|
|
|
relative
|
2023-01-10 07:29:03 +09:00
|
|
|
w-full min-h-50 md:min-h-60
|
2022-12-18 22:22:28 +09:00
|
|
|
justify-center
|
|
|
|
rounded-lg
|
2022-12-18 06:11:39 +09:00
|
|
|
>
|
2022-12-18 22:22:28 +09:00
|
|
|
<div p4 sm:px-8 flex flex-col justify-between min-h-50 md:min-h-60 h-full>
|
|
|
|
<div flex justify-between items-center gap-2 sm:gap-6 h-full mb-2 min-h-35 md:min-h-45>
|
2022-12-18 06:11:39 +09:00
|
|
|
<div flex flex-col gap-2>
|
2023-01-09 22:22:19 +09:00
|
|
|
<NuxtLink flex gap-1 text-xl sm:text-3xl flex-wrap leading-none :href="meta.titleUrl" target="_blank" external>
|
2022-12-18 06:11:39 +09:00
|
|
|
<template v-if="meta.repo">
|
|
|
|
<span>{{ meta.user }}</span><span text-secondary-light>/</span><span text-primary font-bold>{{ meta.repo }}</span>
|
|
|
|
</template>
|
|
|
|
<span v-else>{{ meta.user }}</span>
|
2023-01-09 22:22:19 +09:00
|
|
|
</NuxtLink>
|
|
|
|
<NuxtLink sm:text-lg :href="card.url" target="_blank" external>
|
2023-01-01 23:29:11 +09:00
|
|
|
<span v-if="meta.type === 'issue'" text-secondary-light me-2>
|
2022-12-18 19:26:55 +09:00
|
|
|
#{{ meta.number }}
|
|
|
|
</span>
|
2023-01-01 23:29:11 +09:00
|
|
|
<span v-if="meta.type === 'pull'" text-secondary-light me-2>
|
2022-12-18 06:11:39 +09:00
|
|
|
PR #{{ meta.number }}
|
2022-12-18 19:26:55 +09:00
|
|
|
</span>
|
|
|
|
<span text-secondary leading-tight>{{ meta.details }}</span>
|
2023-01-09 22:22:19 +09:00
|
|
|
</NuxtLink>
|
2022-12-18 06:11:39 +09:00
|
|
|
</div>
|
2023-01-24 07:22:26 +09:00
|
|
|
<div shrink-0 w-18 sm:w-30>
|
2023-01-09 22:22:19 +09:00
|
|
|
<NuxtLink :href="meta.titleUrl" target="_blank" external>
|
2023-01-24 07:22:26 +09:00
|
|
|
<img w-full aspect-square width="112" height="112" rounded-2 :src="meta.avatar">
|
2023-01-09 22:22:19 +09:00
|
|
|
</NuxtLink>
|
2022-12-18 06:11:39 +09:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div flex justify-between>
|
2022-12-21 04:42:28 +09:00
|
|
|
<div v-if="meta.author" flex class="gap-2.5" items-center>
|
2022-12-18 06:11:39 +09:00
|
|
|
<div>
|
2022-12-21 04:42:28 +09:00
|
|
|
<img w-8 aspect-square width="25" height="25" rounded-full :src="meta.author?.avatar">
|
2022-12-18 06:11:39 +09:00
|
|
|
</div>
|
2022-12-21 04:42:28 +09:00
|
|
|
<span text-lg text-primary>@{{ meta.author?.user }}</span>
|
2022-12-18 06:11:39 +09:00
|
|
|
</div>
|
|
|
|
<div v-else />
|
2022-12-21 04:42:28 +09:00
|
|
|
<div text-3xl i-ri:github-fill text-secondary />
|
2022-12-18 06:11:39 +09:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2023-02-02 04:14:23 +09:00
|
|
|
<StatusPreviewCardNormal v-else :card="card" />
|
2022-12-18 06:11:39 +09:00
|
|
|
</template>
|