astro-accelerator-utils 0.2.25 → 0.2.27
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 +6 -0
- package/lib/v1/navigation.mjs +32 -14
- package/package.json +1 -1
- package/types/NavPage.d.ts +1 -0
package/lib/v1/navigation.d.mts
CHANGED
|
@@ -32,6 +32,12 @@ export class Navigation {
|
|
|
32
32
|
* @returns {NavPage[]}
|
|
33
33
|
*/
|
|
34
34
|
menu(currentUrl: URL, subfolder: string, menu: (NavPage | 'auto')[]): NavPage[];
|
|
35
|
+
/**
|
|
36
|
+
*
|
|
37
|
+
* @param {NavPage} page
|
|
38
|
+
* @param {NavPage[]} pageList
|
|
39
|
+
*/
|
|
40
|
+
getChildren(page: NavPage, pageList: NavPage[]): import("../../types/NavPage").NavPage[];
|
|
35
41
|
/**
|
|
36
42
|
*
|
|
37
43
|
* @param {string} subfolder
|
package/lib/v1/navigation.mjs
CHANGED
|
@@ -86,6 +86,36 @@ export class Navigation {
|
|
|
86
86
|
return pages;
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
+
/**
|
|
90
|
+
*
|
|
91
|
+
* @param {NavPage} page
|
|
92
|
+
* @param {NavPage[]} pageList
|
|
93
|
+
*/
|
|
94
|
+
getChildren(page, pageList) {
|
|
95
|
+
const children = pageList
|
|
96
|
+
.filter((mp) =>
|
|
97
|
+
page.url != '/'
|
|
98
|
+
&& mp.url != page.url
|
|
99
|
+
&& mp.url.startsWith(page.url)
|
|
100
|
+
&& mp.url.split('/').length == (page.url.split('/').length + 1)
|
|
101
|
+
)
|
|
102
|
+
.sort((mp) => mp.order);
|
|
103
|
+
|
|
104
|
+
for (let child of children) {
|
|
105
|
+
child.children = this.getChildren(child, pageList);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (children.length > 0) {
|
|
109
|
+
// Add the item to itself as the first item
|
|
110
|
+
const ownChild = structuredClone(page);
|
|
111
|
+
ownChild.order = -1;
|
|
112
|
+
ownChild.children = [];
|
|
113
|
+
children.push(ownChild);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return children;
|
|
117
|
+
}
|
|
118
|
+
|
|
89
119
|
/**
|
|
90
120
|
*
|
|
91
121
|
* @param {string} subfolder
|
|
@@ -112,20 +142,7 @@ export class Navigation {
|
|
|
112
142
|
|
|
113
143
|
if (i > 0) {
|
|
114
144
|
// Don't add children to first link (Home)
|
|
115
|
-
page.children = pageList
|
|
116
|
-
.filter((mp) =>
|
|
117
|
-
page.url != '/'
|
|
118
|
-
&& mp.url != page.url
|
|
119
|
-
&& mp.url.startsWith(page.url)
|
|
120
|
-
)
|
|
121
|
-
.sort((mp) => mp.order);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
if (page.children.length > 0) {
|
|
125
|
-
const ownChild = structuredClone(page);
|
|
126
|
-
ownChild.order = -1;
|
|
127
|
-
ownChild.children = [];
|
|
128
|
-
page.children.push(ownChild);
|
|
145
|
+
page.children = this.getChildren(page, pageList);
|
|
129
146
|
}
|
|
130
147
|
}
|
|
131
148
|
|
|
@@ -347,6 +364,7 @@ export class Navigation {
|
|
|
347
364
|
|
|
348
365
|
/** @type {NavPage} */
|
|
349
366
|
const entry = {
|
|
367
|
+
fullTitle: page.frontmatter.title,
|
|
350
368
|
section: page.frontmatter.navSection ?? page.frontmatter.navTitle ?? page.frontmatter.title,
|
|
351
369
|
title: page.frontmatter.navTitle ?? page.frontmatter.title,
|
|
352
370
|
url: url,
|
package/package.json
CHANGED