astro-accelerator-utils 0.2.25 → 0.2.26

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.
@@ -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
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro-accelerator-utils",
3
- "version": "0.2.25",
3
+ "version": "0.2.26",
4
4
  "description": "Astro utilities for Astro Accelerator.",
5
5
  "main": "index.mjs",
6
6
  "type": "module",