Branchwell

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

Raw 2.3 KB on 443f4fb7f176dfa237ca639945f31e22fbe94e8c
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}
45
46/** Our own domains. Links may only go here; anything else shows as plain text. */
47const OURS = ['skillfarm.ai', 'branchwell.ai', 'projectatom.ai', 'paywell.site', 'freeshift.ai', 'clearmeadow.ai', 'biolock.dev'];
48
49/** True when a link stays on one of our own domains. */
50export function isOurs(url: string | null | undefined): boolean {
51 if (!url) return false;
52 try {
53 const host = new URL(url).hostname.replace(/^www\./, '');
54 return OURS.some((d) => host === d || host.endsWith(`.${d}`));
55 } catch {
56 return false;
57 }
58}