UNPKG

@withstudiocms/internal_helpers

Version:

Internal helper utilities for StudioCMS

29 lines (28 loc) 869 B
import { pathWithBase, stripLeadingAndTrailingSlashes } from "./pathGenerators.js"; function createURLGenFactory(defaultDashboardRoute) { return function urlGenFactory(isDashboardRoute, path, DashboardRouteOverride) { let url; let dashboardRoute = stripLeadingAndTrailingSlashes(defaultDashboardRoute); if (DashboardRouteOverride) { dashboardRoute = stripLeadingAndTrailingSlashes(DashboardRouteOverride); } if (path) { const cleanPath = stripLeadingAndTrailingSlashes(path); if (isDashboardRoute) { url = pathWithBase(`${dashboardRoute}/${cleanPath}`); } else { url = pathWithBase(cleanPath); } } else { if (isDashboardRoute) { url = pathWithBase(dashboardRoute); } else { url = pathWithBase(""); } } return url; }; } export { createURLGenFactory };