1
0
Fork 1
mirror of https://github.com/elk-zone/elk.git synced 2024-11-19 23:40:07 +00:00

fix: support orgs/ and sponsors/ for GitHub cards

This commit is contained in:
patak 2022-12-23 10:08:13 +01:00
parent ef4a240800
commit cc0472b9e6

View file

@ -23,12 +23,28 @@ interface Meta {
const meta = $computed(() => {
const { url } = props.card
const path = url.split('https://github.com/')[1]
const user = path.match(/([\w-]+)(\/|$)/)?.[1]
const repo = path.match(/[\w-]+\/([\w-]+)/)?.[1]
const repoPath = `${user}/${repo}`
const inRepoPath = path.split(`${repoPath}/`)?.[1]
let number: string | undefined
// Supported paths
// /user
// /user/repo
// /user/repo/issues/number.*
// /user/repo/pull/number.*
// /orgs/user.*
const firstName = path.match(/([\w-]+)(\/|$)/)?.[1]
const secondName = path.match(/[\w-]+\/([\w-]+)/)?.[1]
const firstIsUser = firstName !== 'orgs' && firstName !== 'sponsors'
const user = firstIsUser ? firstName : secondName
const repo = firstIsUser ? secondName : undefined
let type: UrlType = repo ? 'repo' : 'user'
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) {
@ -40,8 +56,9 @@ const meta = $computed(() => {
type = 'pull'
}
}
}
const avatar = `https://github.com/${user}.png?size=256`
const details = (props.card.title ?? '').replace('GitHub - ', '').replace(`${repoPath}: `, '').split(' · ')[0]
const author = props.card.authorName
const info = $ref<Meta>({