astro-accelerator-utils 0.1.12 → 0.1.13
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/index.d.mts +2 -1
- package/index.mjs +2 -2
- package/lib/navigation.d.mts +3 -3
- package/lib/navigation.mjs +3 -3
- package/lib/v1/navigation.d.mts +20 -0
- package/lib/v1/navigation.mjs +89 -0
- package/lib/v1/posts.mjs +1 -0
- package/package.json +1 -1
package/index.d.mts
CHANGED
|
@@ -9,5 +9,6 @@ import * as PostFiltering from "./lib/postFiltering.mjs";
|
|
|
9
9
|
import * as PostOrdering from "./lib/postOrdering.mjs";
|
|
10
10
|
import * as PostPaging from "./lib/postPaging.mjs";
|
|
11
11
|
import * as FooterMenu from "./lib/footerMenu.mjs";
|
|
12
|
+
import * as NavigationX from "./lib/navigation.mjs";
|
|
12
13
|
import * as Taxonomy from "./lib/taxonomy.mjs";
|
|
13
|
-
export { Cache, DateFormatter, Markdown, Navigation, Posts, UrlFormatter, PostQueries, PostFiltering, PostOrdering, PostPaging, FooterMenu, Taxonomy };
|
|
14
|
+
export { Cache, DateFormatter, Markdown, Navigation, Posts, UrlFormatter, PostQueries, PostFiltering, PostOrdering, PostPaging, FooterMenu, NavigationX, Taxonomy };
|
package/index.mjs
CHANGED
|
@@ -10,7 +10,7 @@ import * as PostFiltering from './lib/postFiltering.mjs';
|
|
|
10
10
|
import * as PostOrdering from './lib/postOrdering.mjs';
|
|
11
11
|
import * as PostPaging from './lib/postPaging.mjs';
|
|
12
12
|
import * as FooterMenu from './lib/footerMenu.mjs';
|
|
13
|
-
import * as
|
|
13
|
+
import * as NavigationX from './lib/navigation.mjs';
|
|
14
14
|
import * as Taxonomy from './lib/taxonomy.mjs';
|
|
15
15
|
|
|
16
16
|
export {
|
|
@@ -25,6 +25,6 @@ export {
|
|
|
25
25
|
PostOrdering,
|
|
26
26
|
PostPaging,
|
|
27
27
|
FooterMenu,
|
|
28
|
-
|
|
28
|
+
NavigationX,
|
|
29
29
|
Taxonomy
|
|
30
30
|
};
|
package/lib/navigation.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* @deprecated Use Navigation.menu()
|
|
3
3
|
* @param {URL} currentUrl
|
|
4
4
|
* @param {Site} site
|
|
5
5
|
* @param {NavPage | 'auto'} menu
|
|
@@ -7,13 +7,13 @@
|
|
|
7
7
|
*/
|
|
8
8
|
export function getMenu(currentUrl: URL, site: Site, menu: NavPage | 'auto'): Promise<NavPage[]>;
|
|
9
9
|
/**
|
|
10
|
-
*
|
|
10
|
+
* @deprecated Use Navigation.isNavPage
|
|
11
11
|
* @param {NavPage | 'auto' | 'tags' | 'toptags' | 'categories'} item
|
|
12
12
|
* @returns {item is NavPage}
|
|
13
13
|
*/
|
|
14
14
|
export function isNavPage(item: NavPage | 'auto' | 'tags' | 'toptags' | 'categories'): item is import("../types/NavPage").NavPage;
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
16
|
+
* @deprecated Use Navigation.autoMenu()
|
|
17
17
|
* @param {URL} currentUrl
|
|
18
18
|
* @param {Site} site
|
|
19
19
|
* @returns {Promise<NavPage[]}
|
package/lib/navigation.mjs
CHANGED
|
@@ -11,7 +11,7 @@ import * as PostFiltering from './postFiltering.mjs';
|
|
|
11
11
|
const cache = new Cache(200);
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
|
-
*
|
|
14
|
+
* @deprecated Use Navigation.menu()
|
|
15
15
|
* @param {URL} currentUrl
|
|
16
16
|
* @param {Site} site
|
|
17
17
|
* @param {NavPage | 'auto'} menu
|
|
@@ -47,7 +47,7 @@ export async function getMenu (currentUrl, site, menu) {
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
/**
|
|
50
|
-
*
|
|
50
|
+
* @deprecated Use Navigation.isNavPage
|
|
51
51
|
* @param {NavPage | 'auto' | 'tags' | 'toptags' | 'categories'} item
|
|
52
52
|
* @returns {item is NavPage}
|
|
53
53
|
*/
|
|
@@ -61,7 +61,7 @@ export function isNavPage (item) {
|
|
|
61
61
|
|
|
62
62
|
|
|
63
63
|
/**
|
|
64
|
-
*
|
|
64
|
+
* @deprecated Use Navigation.autoMenu()
|
|
65
65
|
* @param {URL} currentUrl
|
|
66
66
|
* @param {Site} site
|
|
67
67
|
* @returns {Promise<NavPage[]}
|
package/lib/v1/navigation.d.mts
CHANGED
|
@@ -18,6 +18,20 @@ export class Navigation {
|
|
|
18
18
|
* @returns {NavPage[]}
|
|
19
19
|
*/
|
|
20
20
|
breadcrumbs(currentUrl: URL, subfolder: string): NavPage[];
|
|
21
|
+
/**
|
|
22
|
+
*
|
|
23
|
+
* @param {URL} currentUrl
|
|
24
|
+
* @param {string} subfolder
|
|
25
|
+
* @param {(NavPage | 'auto')[]} menu
|
|
26
|
+
* @returns {NavPage[]}
|
|
27
|
+
*/
|
|
28
|
+
menu(currentUrl: URL, subfolder: string, menu: (NavPage | 'auto')[]): NavPage[];
|
|
29
|
+
/**
|
|
30
|
+
*
|
|
31
|
+
* @param {string} subfolder
|
|
32
|
+
* @returns {NavPage[]}
|
|
33
|
+
*/
|
|
34
|
+
autoMenu(subfolder: string): NavPage[];
|
|
21
35
|
/**
|
|
22
36
|
* Walks a NavPage tree to set current page
|
|
23
37
|
* @param {NavPage[]} pages
|
|
@@ -30,6 +44,12 @@ export class Navigation {
|
|
|
30
44
|
* @returns {NavPage}
|
|
31
45
|
*/
|
|
32
46
|
mapNavPage(page: MarkdownInstance): NavPage;
|
|
47
|
+
/**
|
|
48
|
+
* Checks whether the item is a NavPage
|
|
49
|
+
* @param {NavPage | 'auto' | 'tags' | 'toptags' | 'categories'} item
|
|
50
|
+
* @returns {item is NavPage}
|
|
51
|
+
*/
|
|
52
|
+
isNavPage(item: NavPage | 'auto' | 'tags' | 'toptags' | 'categories'): item is import("../../types/NavPage").NavPage;
|
|
33
53
|
/**
|
|
34
54
|
* Pops matching page from array
|
|
35
55
|
* @param {MarkdownInstance[]} allPages
|
package/lib/v1/navigation.mjs
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import * as PostFiltering from '../postFiltering.mjs';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* @typedef { import("../../types/Astro").MarkdownInstance } MarkdownInstance
|
|
3
5
|
* @typedef { import("../../types/NavPage").NavPage } NavPage
|
|
@@ -49,6 +51,79 @@ export class Navigation {
|
|
|
49
51
|
return navPages;
|
|
50
52
|
}
|
|
51
53
|
|
|
54
|
+
/**
|
|
55
|
+
*
|
|
56
|
+
* @param {URL} currentUrl
|
|
57
|
+
* @param {string} subfolder
|
|
58
|
+
* @param {(NavPage | 'auto')[]} menu
|
|
59
|
+
* @returns {NavPage[]}
|
|
60
|
+
*/
|
|
61
|
+
menu (currentUrl, subfolder, menu) {
|
|
62
|
+
const pages = [];
|
|
63
|
+
for (let i = 0; i < menu.length; i++) {
|
|
64
|
+
const item = menu[i];
|
|
65
|
+
if (this.isNavPage(item)) {
|
|
66
|
+
pages.push(item);
|
|
67
|
+
} else {
|
|
68
|
+
const p = this.autoMenu(subfolder);
|
|
69
|
+
for (let j = 0; j < p.length; j++) {
|
|
70
|
+
pages.push(p[j]);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
this.setCurrentPage(pages, currentUrl);
|
|
76
|
+
|
|
77
|
+
return pages;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
*
|
|
82
|
+
* @param {string} subfolder
|
|
83
|
+
* @returns {NavPage[]}
|
|
84
|
+
*/
|
|
85
|
+
autoMenu (subfolder) {
|
|
86
|
+
const allPages = this.posts
|
|
87
|
+
.all()
|
|
88
|
+
.filter(PostFiltering.showInMenu);
|
|
89
|
+
|
|
90
|
+
const topLevelPages = this.posts
|
|
91
|
+
.root(subfolder)
|
|
92
|
+
.filter(PostFiltering.showInMenu);
|
|
93
|
+
|
|
94
|
+
const pageHierarchy = topLevelPages
|
|
95
|
+
.map(p => this.mapNavPage(p))
|
|
96
|
+
.sort((a, b) => a.order - b.order);
|
|
97
|
+
|
|
98
|
+
/** @type {NavPage[]} */
|
|
99
|
+
const pageList = allPages.map(p => this.mapNavPage(p));
|
|
100
|
+
|
|
101
|
+
for (let i = 0; i < pageHierarchy.length; i++) {
|
|
102
|
+
const page = pageHierarchy[i];
|
|
103
|
+
|
|
104
|
+
if (i > 0) {
|
|
105
|
+
// Don't add children to first link (Home)
|
|
106
|
+
page.children = pageList
|
|
107
|
+
.filter((mp) =>
|
|
108
|
+
page.url != '/'
|
|
109
|
+
&& mp.url != page.url
|
|
110
|
+
&& mp.url.startsWith(page.url)
|
|
111
|
+
)
|
|
112
|
+
.sort((mp) => mp.order);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (page.children.length > 0) {
|
|
116
|
+
const ownChild = structuredClone(page);
|
|
117
|
+
ownChild.order = -1;
|
|
118
|
+
ownChild.children = [];
|
|
119
|
+
page.children.push(ownChild);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return pageHierarchy;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
|
|
52
127
|
/**
|
|
53
128
|
* Walks a NavPage tree to set current page
|
|
54
129
|
* @param {NavPage[]} pages
|
|
@@ -104,6 +179,20 @@ export class Navigation {
|
|
|
104
179
|
return entry;
|
|
105
180
|
}
|
|
106
181
|
|
|
182
|
+
|
|
183
|
+
/**
|
|
184
|
+
* Checks whether the item is a NavPage
|
|
185
|
+
* @param {NavPage | 'auto' | 'tags' | 'toptags' | 'categories'} item
|
|
186
|
+
* @returns {item is NavPage}
|
|
187
|
+
*/
|
|
188
|
+
isNavPage (item) {
|
|
189
|
+
if (typeof item === 'string' && ['auto', 'tags', 'toptags', 'categories'].includes(item)) {
|
|
190
|
+
return false;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
return true;
|
|
194
|
+
}
|
|
195
|
+
|
|
107
196
|
/**
|
|
108
197
|
* Pops matching page from array
|
|
109
198
|
* @param {MarkdownInstance[]} allPages
|
package/lib/v1/posts.mjs
CHANGED