| | import slash from 'slash' |
| | import path from 'path' |
| | import patterns from './patterns' |
| | import { latest } from '@/versions/lib/enterprise-server-releases' |
| | import { productIds } from '@/products/lib/all-products' |
| | import { allVersions } from '@/versions/lib/all-versions' |
| | import nonEnterpriseDefaultVersion from '@/versions/lib/non-enterprise-default-version' |
| | const supportedVersions = new Set(Object.keys(allVersions)) |
| |
|
| | |
| | |
| | export function getLangFromPath(href: string | undefined): string | null { |
| | if (!href) return null |
| | |
| | const match = getPathWithoutVersion(href).match(patterns.getLanguageCode) |
| | return match ? match[1] : null |
| | } |
| |
|
| | |
| | |
| | export function getPathWithLanguage(href: string | undefined, languageCode: string): string { |
| | if (!href) return `/${languageCode}` |
| | return slash(path.posix.join('/', languageCode, getPathWithoutLanguage(href))).replace( |
| | patterns.trailingSlash, |
| | '$1', |
| | ) |
| | } |
| |
|
| | |
| | |
| | export function getPathWithoutLanguage(href: string | undefined): string { |
| | if (!href) return '/' |
| | return slash(href.replace(patterns.hasLanguageCode, '/')) |
| | } |
| |
|
| | |
| | export function getPathWithoutVersion(href: string | undefined): string { |
| | if (!href) return '/' |
| | const versionFromPath = getVersionStringFromPath(href) |
| |
|
| | |
| | return allVersions[versionFromPath] |
| | ? href.replace(`/${getVersionStringFromPath(href)}`, '') |
| | : href |
| | } |
| |
|
| | |
| | export function getVersionStringFromPath( |
| | href: string | undefined, |
| | supportedOnly: true, |
| | ): string | undefined |
| | export function getVersionStringFromPath(href: string | undefined, supportedOnly?: false): string |
| | export function getVersionStringFromPath( |
| | href: string | undefined, |
| | supportedOnly = false, |
| | ): string | undefined { |
| | if (!href) return nonEnterpriseDefaultVersion |
| | href = getPathWithoutLanguage(href) |
| |
|
| | |
| | |
| | if (['/', '/categories.json'].includes(href)) { |
| | return nonEnterpriseDefaultVersion |
| | } |
| |
|
| | |
| | const versionFromPath = href.split('/')[1] |
| |
|
| | |
| | if (productIds.includes(versionFromPath)) { |
| | return nonEnterpriseDefaultVersion |
| | } |
| |
|
| | |
| | if (supportedVersions.has(versionFromPath)) { |
| | return versionFromPath |
| | } |
| |
|
| | |
| | if (versionFromPath === 'enterprise-server@latest') { |
| | return `enterprise-server@${latest}` |
| | } |
| |
|
| | |
| | const planObject = Object.values(allVersions).find((v) => v.plan === versionFromPath) |
| | if (planObject) { |
| | return allVersions[planObject.latestVersion].version |
| | } |
| |
|
| | |
| | |
| | |
| | |
| | |
| | |
| | if (supportedOnly) { |
| | return |
| | } |
| |
|
| | |
| | |
| | return versionFromPath |
| | } |
| |
|
| | |
| | export function getVersionObjectFromPath(href: string | undefined) { |
| | const versionFromPath = getVersionStringFromPath(href, false) |
| |
|
| | return allVersions[versionFromPath] |
| | } |
| |
|
| | |
| | |
| | export function getProductStringFromPath(href: string | undefined): string { |
| | if (!href) return 'homepage' |
| | href = getPathWithoutLanguage(href) |
| |
|
| | if (href === '/') return 'homepage' |
| |
|
| | |
| | const pathParts = href.split('/') |
| |
|
| | if (pathParts.includes('early-access')) return 'early-access' |
| |
|
| | |
| | |
| | if (pathParts[1] === 'rest') return 'rest' |
| | if (pathParts[1] === 'copilot') return 'copilot' |
| | if (pathParts[1] === 'get-started') return 'get-started' |
| |
|
| | |
| | |
| | |
| | |
| | |
| | const isEnterprise = supportedVersions.has(pathParts[1]) |
| | const productString = isEnterprise && pathParts[2] ? pathParts[2] : pathParts[1] |
| | return productString |
| | } |
| |
|
| | export function getCategoryStringFromPath(href: string | undefined): string | undefined { |
| | if (!href) return undefined |
| | href = getPathWithoutLanguage(href) |
| |
|
| | if (href === '/') return undefined |
| |
|
| | const pathParts = href.split('/') |
| |
|
| | if (pathParts.includes('early-access')) return undefined |
| |
|
| | const productIndex = productIds.includes(pathParts[2]) ? 2 : 1 |
| |
|
| | return pathParts[productIndex + 1] |
| | } |
| |
|
| | export default { |
| | getPathWithLanguage, |
| | getPathWithoutLanguage, |
| | getPathWithoutVersion, |
| | getVersionStringFromPath, |
| | getVersionObjectFromPath, |
| | getProductStringFromPath, |
| | getCategoryStringFromPath, |
| | } |
| |
|