MCPcopy Create free account
hub / github.com/error311/FileRise / getBasePath

Function getBasePath

public/js/basePath.js:13–33  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

11
12// Best-effort auto-detect from the *current URL* (works for /fr/, /fr/index.html, etc.).
13export 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
35export function withBase(urlOrPath) {
36 const base = getBasePath();

Callers 4

withBaseFunction · 0.85
stripBaseFunction · 0.85
patchFetchForBasePathFunction · 0.85
main.jsFile · 0.85

Calls 1

normalizeBasePathFunction · 0.85

Tested by

no test coverage detected