Branchwell

Skillfarm / website · skillfarm.ai / src / lib / hosts.ts

Raw 1.8 KB on 947b01baffc181407e99132c54709fba5e84ae85
1/** Skillfarm's own repos live on Branchwell, not GitHub. Other makers' repos stay on GitHub. */
2export 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. */
5const 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. */
10export 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. */
15export 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. */
23export 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. */
29export 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". */
34export 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}