()
| 11 | |
| 12 | // Best-effort auto-detect from the *current URL* (works for /fr/, /fr/index.html, etc.). |
| 13 | export function getBasePath() { |
| 14 | try { |
| 15 | let p = String(window.location.pathname || ''); |
| 16 | |
| 17 | // Pretty portal URL: /portal/<slug> (or /fr/portal/<slug>) |
| 18 | p = p.replace(/\/portal\/[^/]+\/?$/i, ''); |
| 19 | |
| 20 | // Common "file" entrypoints |
| 21 | p = p.replace(/\/index\.html$/i, ''); |
| 22 | p = p.replace(/\/portal-login\.html$/i, ''); |
| 23 | p = p.replace(/\/portal\.html$/i, ''); |
| 24 | p = p.replace(/\/api\.php$/i, ''); |
| 25 | |
| 26 | // Directory root -> base without trailing slash |
| 27 | p = p.replace(/\/+$/, ''); |
| 28 | |
| 29 | return normalizeBasePath(p); |
| 30 | } catch (e) { |
| 31 | return ''; |
| 32 | } |
| 33 | } |
| 34 | |
| 35 | export function withBase(urlOrPath) { |
| 36 | const base = getBasePath(); |
no test coverage detected