fix: support orgs/ and sponsors/ for GitHub cards

zio/stable
patak 2022-12-23 10:08:13 +01:00
parent ef4a240800
commit cc0472b9e6
1 changed files with 32 additions and 15 deletions

View File

@ -23,25 +23,42 @@ interface Meta {
const meta = $computed(() => { const meta = $computed(() => {
const { url } = props.card const { url } = props.card
const path = url.split('https://github.com/')[1] const path = url.split('https://github.com/')[1]
const user = path.match(/([\w-]+)(\/|$)/)?.[1]
const repo = path.match(/[\w-]+\/([\w-]+)/)?.[1] // Supported paths
const repoPath = `${user}/${repo}` // /user
const inRepoPath = path.split(`${repoPath}/`)?.[1] // /user/repo
let number: string | undefined // /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 type: UrlType = repo ? 'repo' : 'user'
if (inRepoPath) { let number: string | undefined
number = inRepoPath.match(/issues\/(\d+)/)?.[1] let details = (props.card.title ?? '').replace('GitHub - ', '').split(' · ')[0]
if (number) {
type = 'issue' if (repo) {
} const repoPath = `${user}/${repo}`
else { details = details.replace(`${repoPath}: `, '')
number = inRepoPath.match(/pull\/(\d+)/)?.[1] const inRepoPath = path.split(`${repoPath}/`)?.[1]
if (number) if (inRepoPath) {
type = 'pull' number = inRepoPath.match(/issues\/(\d+)/)?.[1]
if (number) {
type = 'issue'
}
else {
number = inRepoPath.match(/pull\/(\d+)/)?.[1]
if (number)
type = 'pull'
}
} }
} }
const avatar = `https://github.com/${user}.png?size=256` 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 author = props.card.authorName
const info = $ref<Meta>({ const info = $ref<Meta>({