2022-12-18 00:11:39 +03:00
|
|
|
<script setup lang="ts">
|
|
|
|
import type { Card } from 'masto'
|
|
|
|
|
|
|
|
const props = defineProps<{
|
|
|
|
card: Card
|
|
|
|
}>()
|
|
|
|
|
|
|
|
type UrlType = 'user' | 'repo' | 'issue' | 'pull'
|
|
|
|
interface Meta {
|
|
|
|
type: UrlType
|
2022-12-19 15:29:16 +03:00
|
|
|
user?: string
|
2022-12-18 16:22:28 +03:00
|
|
|
titleUrl: string
|
2022-12-18 00:11:39 +03:00
|
|
|
avatar: string
|
|
|
|
details: string
|
|
|
|
repo?: string
|
|
|
|
number?: string
|
2022-12-20 22:42:28 +03:00
|
|
|
author?: {
|
|
|
|
avatar: string
|
|
|
|
user: string
|
2022-12-18 00:11:39 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-03 18:59:49 +03:00
|
|
|
const specialRoutes = ['orgs', 'sponsors', 'stars']
|
|
|
|
|
2022-12-18 00:11:39 +03:00
|
|
|
const meta = $computed(() => {
|
|
|
|
const { url } = props.card
|
|
|
|
const path = url.split('https://github.com/')[1]
|
2022-12-23 12:08:13 +03:00
|
|
|
|
|
|
|
// Supported paths
|
|
|
|
// /user
|
|
|
|
// /user/repo
|
2023-01-03 18:59:49 +03:00
|
|
|
// /user/repo/issues/number
|
|
|
|
// /user/repo/pull/number
|
|
|
|
// /orgs/user
|
|
|
|
// /sponsors/user
|
|
|
|
// /stars/user
|
2022-12-23 12:08:13 +03:00
|
|
|
|
|
|
|
const firstName = path.match(/([\w-]+)(\/|$)/)?.[1]
|
|
|
|
const secondName = path.match(/[\w-]+\/([\w-]+)/)?.[1]
|
2023-01-03 18:59:49 +03:00
|
|
|
const firstIsUser = firstName && !specialRoutes.includes(firstName)
|
2022-12-23 12:08:13 +03:00
|
|
|
const user = firstIsUser ? firstName : secondName
|
|
|
|
const repo = firstIsUser ? secondName : undefined
|
|
|
|
|
2022-12-18 00:11:39 +03:00
|
|
|
let type: UrlType = repo ? 'repo' : 'user'
|
2022-12-23 12:08:13 +03: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 00:11:39 +03:00
|
|
|
}
|
|
|
|
}
|
2022-12-23 12:08:13 +03:00
|
|
|
|
2022-12-20 22:42:28 +03:00
|
|
|
const avatar = `https://github.com/${user}.png?size=256`
|
|
|
|
|
|
|
|
const author = props.card.authorName
|
2022-12-18 00:11:39 +03:00
|
|
|
const info = $ref<Meta>({
|
|
|
|
type,
|
|
|
|
user,
|
2022-12-18 16:22:28 +03:00
|
|
|
titleUrl: `https://github.com/${user}${repo ? `/${repo}` : ''}`,
|
2022-12-18 00:11:39 +03:00
|
|
|
details,
|
|
|
|
repo,
|
|
|
|
number,
|
|
|
|
avatar,
|
2022-12-20 22:42:28 +03:00
|
|
|
author: author
|
|
|
|
? {
|
|
|
|
avatar: `https://github.com/${author}.png?size=64`,
|
|
|
|
user: author,
|
|
|
|
}
|
|
|
|
: undefined,
|
2022-12-18 00:11:39 +03:00
|
|
|
})
|
|
|
|
return info
|
|
|
|
})
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<template>
|
|
|
|
<div
|
|
|
|
v-if="card.image"
|
|
|
|
flex flex-col
|
|
|
|
display-block of-hidden
|
|
|
|
bg-code
|
|
|
|
relative
|
|
|
|
border="base"
|
2022-12-18 16:22:28 +03:00
|
|
|
w-full min-h-50 md:min-h-60 border-b
|
|
|
|
justify-center
|
|
|
|
rounded-lg
|
2022-12-18 00:11:39 +03:00
|
|
|
>
|
2022-12-18 16:22:28 +03: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 00:11:39 +03:00
|
|
|
<div flex flex-col gap-2>
|
2022-12-18 16:22:28 +03:00
|
|
|
<a flex gap-1 text-xl sm:text-3xl flex-wrap leading-none :href="meta.titleUrl" target="_blank">
|
2022-12-18 00:11:39 +03: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>
|
|
|
|
</a>
|
2022-12-18 16:22:28 +03:00
|
|
|
<a sm:text-lg :href="card.url" target="_blank">
|
2023-01-01 17:29:11 +03:00
|
|
|
<span v-if="meta.type === 'issue'" text-secondary-light me-2>
|
2022-12-18 13:26:55 +03:00
|
|
|
#{{ meta.number }}
|
|
|
|
</span>
|
2023-01-01 17:29:11 +03:00
|
|
|
<span v-if="meta.type === 'pull'" text-secondary-light me-2>
|
2022-12-18 00:11:39 +03:00
|
|
|
PR #{{ meta.number }}
|
2022-12-18 13:26:55 +03:00
|
|
|
</span>
|
|
|
|
<span text-secondary leading-tight>{{ meta.details }}</span>
|
2022-12-18 16:22:28 +03:00
|
|
|
</a>
|
2022-12-18 00:11:39 +03:00
|
|
|
</div>
|
|
|
|
<div>
|
2022-12-18 16:22:28 +03:00
|
|
|
<a :href="meta.titleUrl" target="_blank">
|
|
|
|
<img w-30 aspect-square width="20" height="20" rounded-2 :src="meta.avatar">
|
|
|
|
</a>
|
2022-12-18 00:11:39 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div flex justify-between>
|
2022-12-20 22:42:28 +03:00
|
|
|
<div v-if="meta.author" flex class="gap-2.5" items-center>
|
2022-12-18 00:11:39 +03:00
|
|
|
<div>
|
2022-12-20 22:42:28 +03:00
|
|
|
<img w-8 aspect-square width="25" height="25" rounded-full :src="meta.author?.avatar">
|
2022-12-18 00:11:39 +03:00
|
|
|
</div>
|
2022-12-20 22:42:28 +03:00
|
|
|
<span text-lg text-primary>@{{ meta.author?.user }}</span>
|
2022-12-18 00:11:39 +03:00
|
|
|
</div>
|
|
|
|
<div v-else />
|
2022-12-20 22:42:28 +03:00
|
|
|
<div text-3xl i-ri:github-fill text-secondary />
|
2022-12-18 00:11:39 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|