Skillfarm / website · skillfarm.ai / src / lib / hosts.ts
| 1 | /** Skillfarm's own repos live on Branchwell, not GitHub. Other makers' repos stay on GitHub. */ |
| 2 | export const BRANCHWELL = 'https://branchwell.ai'; |
| 3 | |
| 4 | /** Repo names still stored in the database for Skillfarm's own skills, and where each one lives on Branchwell. */ |
| 5 | const OWN_REPOS: Record<string, string> = { |
| 6 | 'projectatomai/skills': 'skillfarm/skills', |
| 7 | }; |
| 8 | |
| 9 | /** The Branchwell owner/project for one of Skillfarm's own repos, or null for anyone else's repo. */ |
| 10 | export function ownRepo(repo: string | null | undefined): string | null { |
| 11 | return repo ? OWN_REPOS[repo.toLowerCase()] ?? null : null; |
| 12 | } |
| 13 | |
| 14 | /** The web address of a repo, or of a folder in it, on the host where it lives. */ |
| 15 | export function repoWebUrl(repo: string, path?: string | null, ref?: string | null): string { |
| 16 | const own = ownRepo(repo); |
| 17 | const clean = (path ?? '').replace(/^\/+|\/+$/g, ''); |
| 18 | if (own) return `${BRANCHWELL}/${own}${clean ? `/tree/main/${clean}` : ''}`; |
| 19 | return `https://github.com/${repo}${clean ? `/tree/${ref ?? 'HEAD'}/${clean}` : ''}`; |
| 20 | } |
| 21 | |
| 22 | /** The address to clone a repo from. */ |
| 23 | export function repoCloneUrl(repo: string): string { |
| 24 | const own = ownRepo(repo); |
| 25 | return own ? `${BRANCHWELL}/${own}.git` : `https://github.com/${repo}.git`; |
| 26 | } |
| 27 | |
| 28 | /** The repo name to show people: Skillfarm's own repos show their Branchwell name. */ |
| 29 | export function repoLabel(repo: string): string { |
| 30 | return ownRepo(repo) ?? repo; |
| 31 | } |
| 32 | |
| 33 | /** The name of the site a link goes to, for button text such as "Get it on Branchwell". */ |
| 34 | export function hostName(url: string): string { |
| 35 | try { |
| 36 | const host = new URL(url).hostname.replace(/^www\./, ''); |
| 37 | if (host === 'branchwell.ai') return 'Branchwell'; |
| 38 | if (host === 'github.com') return 'GitHub'; |
| 39 | if (host === 'gitlab.com') return 'GitLab'; |
| 40 | return host; |
| 41 | } catch { |
| 42 | return 'the maker\'s site'; |
| 43 | } |
| 44 | } |