|
| 1 | +export type RouteKey = |
| 2 | + | "home" |
| 3 | + | "services" |
| 4 | + | "servicesDevelopment" |
| 5 | + | "servicesDesign" |
| 6 | + | "servicesInfrastructure" |
| 7 | + | "servicesDeployment" |
| 8 | + | "servicesPostLaunch" |
| 9 | + | "contact" |
| 10 | + | "caseStudies" |
| 11 | + | "caseStudy" |
| 12 | + | "howWeWork" |
| 13 | + | "faq" |
| 14 | + | "forFounders"; |
| 15 | + |
| 16 | +export type RouteParams = { |
| 17 | + slug?: string; |
| 18 | +}; |
| 19 | + |
| 20 | +type RouteBuilder = (params?: RouteParams) => string; |
| 21 | + |
| 22 | +type RouteEntry = { |
| 23 | + pl: string | RouteBuilder; |
| 24 | + en: string | RouteBuilder; |
| 25 | +}; |
| 26 | + |
| 27 | +const buildCaseStudyPath = (basePath: string): RouteBuilder => (params) => { |
| 28 | + if (!params?.slug) { |
| 29 | + throw new Error("Missing slug for case study route."); |
| 30 | + } |
| 31 | + |
| 32 | + return `${basePath}${params.slug}/`; |
| 33 | +}; |
| 34 | + |
| 35 | +const routes: Record<RouteKey, RouteEntry> = { |
| 36 | + home: { |
| 37 | + pl: "/pl/", |
| 38 | + en: "/en/", |
| 39 | + }, |
| 40 | + services: { |
| 41 | + pl: "/pl/oferta/", |
| 42 | + en: "/en/services/", |
| 43 | + }, |
| 44 | + servicesDevelopment: { |
| 45 | + pl: "/pl/oferta/programowanie/", |
| 46 | + en: "/en/services/development/", |
| 47 | + }, |
| 48 | + servicesDesign: { |
| 49 | + pl: "/pl/oferta/projektowanie/", |
| 50 | + en: "/en/services/design/", |
| 51 | + }, |
| 52 | + servicesInfrastructure: { |
| 53 | + pl: "/pl/oferta/infrastruktura/", |
| 54 | + en: "/en/services/infrastructure/", |
| 55 | + }, |
| 56 | + servicesDeployment: { |
| 57 | + pl: "/pl/oferta/wdrozenie/", |
| 58 | + en: "/en/services/deployment/", |
| 59 | + }, |
| 60 | + servicesPostLaunch: { |
| 61 | + pl: "/pl/oferta/obsluga/", |
| 62 | + en: "/en/services/post-launch/", |
| 63 | + }, |
| 64 | + contact: { |
| 65 | + pl: "/pl/kontakt/", |
| 66 | + en: "/en/contact/", |
| 67 | + }, |
| 68 | + caseStudies: { |
| 69 | + pl: "/pl/case-studies/", |
| 70 | + en: "/en/case-studies/", |
| 71 | + }, |
| 72 | + caseStudy: { |
| 73 | + pl: buildCaseStudyPath("/pl/case-studies/"), |
| 74 | + en: buildCaseStudyPath("/en/case-studies/"), |
| 75 | + }, |
| 76 | + howWeWork: { |
| 77 | + pl: "/pl/how-we-work/", |
| 78 | + en: "/en/how-we-work/", |
| 79 | + }, |
| 80 | + faq: { |
| 81 | + pl: "/pl/faq/", |
| 82 | + en: "/en/faq/", |
| 83 | + }, |
| 84 | + forFounders: { |
| 85 | + pl: "/pl/for-founders/", |
| 86 | + en: "/en/for-founders/", |
| 87 | + }, |
| 88 | +}; |
| 89 | + |
| 90 | +const resolvePath = (value: string | RouteBuilder, params?: RouteParams): string => |
| 91 | + typeof value === "function" ? value(params) : value; |
| 92 | + |
| 93 | +export const getRoutePaths = ( |
| 94 | + routeKey: RouteKey, |
| 95 | + params?: RouteParams, |
| 96 | +): { pl: string; en: string } => { |
| 97 | + const entry = routes[routeKey]; |
| 98 | + |
| 99 | + return { |
| 100 | + pl: resolvePath(entry.pl, params), |
| 101 | + en: resolvePath(entry.en, params), |
| 102 | + }; |
| 103 | +}; |
0 commit comments