| 1 | import { desktopDownload, type DesktopReleaseFact, DESKTOP_RELEASE } from "./desktop-release"; |
| 2 | |
| 3 | export interface RouteRedirect { |
| 4 | to: string; |
| 5 | status: 307 | 308; |
| 6 | } |
| 7 | |
| 8 | export const PERMANENT_ROUTE_REDIRECTS: Readonly<Record<string, string>> = { |
| 9 | community: "/contribute", |
| 10 | feed: "/contribute", |
| 11 | roadmap: "/contribute#milestones", |
| 12 | digest: "/changelog", |
| 13 | product: "", |
| 14 | runtime: "/docs/runtime-api", |
| 15 | constitution: "/docs/constitution", |
| 16 | enterprise: "/faq#teams", |
| 17 | security: "/docs/trust", |
| 18 | trust: "/docs/trust", |
| 19 | }; |
| 20 | |
| 21 | export const INSTALL_OR_APP_ROUTES: readonly string[] = ["download"]; |
| 22 | |
| 23 | export const APP_ROUTES: readonly string[] = ["desktop"]; |
| 24 | |
| 25 | export const INSTALL_ALIAS_ROUTES: readonly string[] = ["pricing"]; |
| 26 | |
| 27 | export const REDIRECTED_ROUTES: readonly string[] = [ |
| 28 | ...Object.keys(PERMANENT_ROUTE_REDIRECTS), |
| 29 | ...INSTALL_OR_APP_ROUTES, |
| 30 | ...APP_ROUTES, |
| 31 | ...INSTALL_ALIAS_ROUTES, |
| 32 | ]; |
| 33 | |
| 34 | export function routeRedirect( |
| 35 | segment: string, |
| 36 | release: DesktopReleaseFact | null = DESKTOP_RELEASE, |
| 37 | ): RouteRedirect | null { |
| 38 | const key = segment.toLowerCase(); |
| 39 | if (Object.hasOwn(PERMANENT_ROUTE_REDIRECTS, key)) { |
| 40 | return { to: PERMANENT_ROUTE_REDIRECTS[key], status: 308 }; |
| 41 | } |
| 42 | if (INSTALL_OR_APP_ROUTES.includes(key)) { |
| 43 | return { to: desktopDownload(release) ? "/app" : "/install", status: 307 }; |
| 44 | } |
| 45 | if (APP_ROUTES.includes(key)) return { to: "/app", status: 307 }; |
| 46 | if (INSTALL_ALIAS_ROUTES.includes(key)) return { to: "/install", status: 307 }; |
| 47 | return null; |
| 48 | } |
| 49 |