File size: 1,468 Bytes
4bbfe8b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { route as localeRoute, strip as localeStrip } from "../../../../console/app/src/lib/language"
import type { Locale } from "../../../../console/app/src/lib/language"

export {
  LOCALES,
  LOCALE_COOKIE,
  LOCALE_HEADER,
  clearCookie,
  cookie,
  detectFromAcceptLanguage,
  detectFromLanguages,
  dir,
  fromPathname,
  label,
  localeFromCookieHeader,
  localeFromRequest,
  parseLocale,
  tag,
} from "../../../../console/app/src/lib/language"

export type { Locale } from "../../../../console/app/src/lib/language"

export const basePath = "/data"
export const baseUrl = "https://opencode.ai"

function normalizeDataPathname(pathname: string) {
  const next = localeStrip(pathname)
  const path = next.startsWith("/") ? next : `/${next}`
  const trailing = path.endsWith("/")
  const segments = path.split("/").filter(Boolean)
  const dataIndex = segments.lastIndexOf(basePath.slice(1))
  const rest = dataIndex === -1 ? segments : segments.slice(dataIndex + 1)
  const normalized = `${basePath}${rest.length ? `/${rest.join("/")}` : "/"}`
  if (trailing && !normalized.endsWith("/")) return `${normalized}/`
  return normalized
}

export function strip(pathname: string) {
  return normalizeDataPathname(pathname)
}

export function route(locale: Locale, pathname: string) {
  return localeRoute(locale, normalizeDataPathname(pathname))
}

export function localizedUrl(locale: Locale, pathname: string) {
  return `${baseUrl}${route(locale, pathname)}`
}