@deepsel/cms-utils
Advanced tools
@@ -8,15 +8,20 @@ // Check if a menu item should be marked as active | ||
| const currentLang = websiteData.data.lang; | ||
| let result; | ||
| if (menuItem.url === '/') { | ||
| result = pathname === '/' || pathname === `/${currentLang}` || pathname === `/${currentLang}/`; | ||
| const isMatch = (url) => { | ||
| const p = pathname.replace(/\/$/, '') || '/'; | ||
| const u = url.replace(/\/$/, '') || '/'; | ||
| return p === u || p.startsWith(u + '/'); | ||
| }; | ||
| let result = false; | ||
| if (menuItem.url) { | ||
| result = isMatch(menuItem.url) || isMatch(`/${currentLang}${menuItem.url}`); | ||
| } | ||
| else if (menuItem.url) { | ||
| result = | ||
| pathname === menuItem.url || | ||
| pathname === `/${currentLang}${menuItem.url}` || | ||
| pathname === `/${currentLang}${menuItem.url}/` || | ||
| pathname.startsWith(menuItem.url + '/') || | ||
| pathname.startsWith(`/${currentLang}${menuItem.url}/`); | ||
| // Also mark parent active if any child matches | ||
| if (!result && menuItem.children?.length) { | ||
| result = menuItem.children.some((child) => { | ||
| if (!child.url) | ||
| return false; | ||
| return isMatch(child.url) || isMatch(`/${currentLang}${child.url}`); | ||
| }); | ||
| } | ||
| return result ?? false; | ||
| return result; | ||
| }; |
+3
-1
| { | ||
| "name": "@deepsel/cms-utils", | ||
| "version": "1.9.5", | ||
| "version": "1.9.6", | ||
| "description": "Helper utilities for Deepsel CMS", | ||
@@ -28,2 +28,3 @@ "repository": { | ||
| ".": { | ||
| "source": "./src/index.ts", | ||
| "import": "./dist/index.js", | ||
@@ -33,2 +34,3 @@ "types": "./dist/index.d.ts" | ||
| "./common/utils": { | ||
| "source": "./src/common/utils/index.ts", | ||
| "import": "./dist/common/utils/index.js", | ||
@@ -35,0 +37,0 @@ "types": "./dist/common/utils/index.d.ts" |
52390
0.38%1470
0.34%