astro-accelerator-utils 0.3.97 → 0.3.98
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/v1/navigation.d.mts +12 -0
- package/lib/v1/navigation.mjs +27 -2
- package/package.json +1 -1
package/lib/v1/navigation.d.mts
CHANGED
|
@@ -103,6 +103,18 @@ export class Navigation {
|
|
|
103
103
|
* @returns {item is NavPage}
|
|
104
104
|
*/
|
|
105
105
|
isNavPage(item: NavPage | "auto" | "tags" | "toptags" | "categories"): item is NavPage;
|
|
106
|
+
/**
|
|
107
|
+
* Counts non-empty path segments so trailing slashes do not affect depth
|
|
108
|
+
* @param {string | null | undefined} path
|
|
109
|
+
* @returns {number}
|
|
110
|
+
*/
|
|
111
|
+
pathDepth(path: string | null | undefined): number;
|
|
112
|
+
/**
|
|
113
|
+
* Normalizes a path for comparison by joining non-empty segments
|
|
114
|
+
* @param {string | null | undefined} path
|
|
115
|
+
* @returns {string}
|
|
116
|
+
*/
|
|
117
|
+
normalizePath(path: string | null | undefined): string;
|
|
106
118
|
/**
|
|
107
119
|
* Pops matching page from array
|
|
108
120
|
* @param {MarkdownInstance[]} allPages
|
package/lib/v1/navigation.mjs
CHANGED
|
@@ -120,7 +120,7 @@ export class Navigation {
|
|
|
120
120
|
page.url != '/'
|
|
121
121
|
&& mp.url != page.url
|
|
122
122
|
&& mp.url.startsWith(page.url)
|
|
123
|
-
&& mp.url
|
|
123
|
+
&& this.pathDepth(mp.url) == (this.pathDepth(page.url) + 1)
|
|
124
124
|
)
|
|
125
125
|
.sort((mp) => mp.order);
|
|
126
126
|
|
|
@@ -458,6 +458,30 @@ export class Navigation {
|
|
|
458
458
|
return true;
|
|
459
459
|
}
|
|
460
460
|
|
|
461
|
+
/**
|
|
462
|
+
* Counts non-empty path segments so trailing slashes do not affect depth
|
|
463
|
+
* @param {string | null | undefined} path
|
|
464
|
+
* @returns {number}
|
|
465
|
+
*/
|
|
466
|
+
pathDepth(path) {
|
|
467
|
+
const url = path ?? '/';
|
|
468
|
+
return url.split('/').filter((segment) => segment.length > 0).length;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
/**
|
|
472
|
+
* Normalizes a path for comparison by joining non-empty segments
|
|
473
|
+
* @param {string | null | undefined} path
|
|
474
|
+
* @returns {string}
|
|
475
|
+
*/
|
|
476
|
+
normalizePath(path) {
|
|
477
|
+
const depth = this.pathDepth(path);
|
|
478
|
+
if (depth === 0) {
|
|
479
|
+
return '/';
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
return '/' + (path ?? '/').split('/').filter((segment) => segment.length > 0).join('/');
|
|
483
|
+
}
|
|
484
|
+
|
|
461
485
|
/**
|
|
462
486
|
* Pops matching page from array
|
|
463
487
|
* @param {MarkdownInstance[]} allPages
|
|
@@ -468,9 +492,10 @@ export class Navigation {
|
|
|
468
492
|
const numberToRemove = 1;
|
|
469
493
|
let indexToRemove = -1;
|
|
470
494
|
let match = null;
|
|
495
|
+
const normalizedSearch = this.normalizePath(search);
|
|
471
496
|
|
|
472
497
|
for (let i = 0; i < allPages.length; i++) {
|
|
473
|
-
if (allPages[i].url
|
|
498
|
+
if (this.normalizePath(allPages[i].url) === normalizedSearch) {
|
|
474
499
|
indexToRemove = i;
|
|
475
500
|
match = allPages[i];
|
|
476
501
|
}
|