UNPKG

@mintlify/common

Version:

Commonly shared code within Mintlify

42 lines (41 loc) 1.62 kB
function parseOwnerRepo(repoUrl) { const patterns = [ /^https?:\/\/github\.com\/([^/]+)\/([^/]+?)(?:\.git)?(?:\/|$)/, /^github\.com\/([^/]+)\/([^/]+?)(?:\.git)?$/, /^([^/]+)\/([^/]+)$/, ]; for (const pattern of patterns) { const match = repoUrl.match(pattern); if ((match === null || match === void 0 ? void 0 : match[1]) && match[2]) { return { owner: match[1], repo: match[2].replace(/\.git$/, '') }; } } return null; } function getSubdomain(deployment) { if (deployment.auth) { switch (deployment.basePath) { case '/docs': return 'mintlify-auth-docs.com'; default: { return 'mintlify.site'; } } } return 'mintlify.site'; } export function getDisplayDomain(deployment, isDev = false, appendBasePath = true) { var _a, _b, _c, _d; const { subdomain } = deployment; if ((_a = deployment.atlas) === null || _a === void 0 ? void 0 : _a.repoUrl) { const parsed = parseOwnerRepo(deployment.atlas.repoUrl); if (parsed) { return `mintlify.com/${parsed.owner}/${parsed.repo}`; } } if (isDev && !((_b = deployment.customDomains) === null || _b === void 0 ? void 0 : _b[0])) { return `${subdomain}.mintlifytest.com`; } const displayDomainBase = (_d = (_c = deployment.customDomains) === null || _c === void 0 ? void 0 : _c[0]) !== null && _d !== void 0 ? _d : `${subdomain}.${getSubdomain(deployment)}`; return displayDomainBase + (appendBasePath ? deployment.basePath : ''); }