astro-accelerator-utils 0.2.39 → 0.2.40
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/README.md +11 -0
- package/lib/v1/navigation.d.mts +5 -11
- package/lib/v1/navigation.mjs +13 -4
- package/package.json +2 -1
- package/types/NavPage.d.ts +11 -0
package/README.md
CHANGED
|
@@ -7,3 +7,14 @@ Utility classes for Astro Accelerator
|
|
|
7
7
|
[](https://www.npmjs.com/package/astro-accelerator-utils/)
|
|
8
8
|
[](https://www.npmjs.com/package/astro-accelerator-utils/)
|
|
9
9
|
|
|
10
|
+
## Update Type Information
|
|
11
|
+
|
|
12
|
+
Run the command:
|
|
13
|
+
|
|
14
|
+
pnpm types
|
|
15
|
+
|
|
16
|
+
## Running Tests
|
|
17
|
+
|
|
18
|
+
Run the command:
|
|
19
|
+
|
|
20
|
+
pnpm test
|
package/lib/v1/navigation.d.mts
CHANGED
|
@@ -1,10 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @typedef { import("./posts.mjs").Posts } Posts
|
|
3
|
-
* @typedef { import("./taxonomy.mjs").Taxonomy } Taxonomy
|
|
4
|
-
* @typedef { import("./urls.mjs").UrlFormatter } UrlFormatter
|
|
5
|
-
* @typedef { import("../../types/Astro").MarkdownInstance } MarkdownInstance
|
|
6
|
-
* @typedef { import("../../types/NavPage").NavPage } NavPage
|
|
7
|
-
*/
|
|
8
1
|
export class Navigation {
|
|
9
2
|
/**
|
|
10
3
|
* Constructor
|
|
@@ -28,10 +21,10 @@ export class Navigation {
|
|
|
28
21
|
*
|
|
29
22
|
* @param {URL} currentUrl
|
|
30
23
|
* @param {string} subfolder
|
|
31
|
-
* @param {(
|
|
24
|
+
* @param {(MenuItem | 'auto')[]} menu
|
|
32
25
|
* @returns {NavPage[]}
|
|
33
26
|
*/
|
|
34
|
-
menu(currentUrl: URL, subfolder: string, menu: (
|
|
27
|
+
menu(currentUrl: URL, subfolder: string, menu: (MenuItem | 'auto')[]): NavPage[];
|
|
35
28
|
/**
|
|
36
29
|
*
|
|
37
30
|
* @param {NavPage} page
|
|
@@ -50,10 +43,10 @@ export class Navigation {
|
|
|
50
43
|
* @param {TranslationProvider} _
|
|
51
44
|
* @param {any} translations
|
|
52
45
|
* @param {string} subfolder
|
|
53
|
-
* @param {(
|
|
46
|
+
* @param {(MenuItem | 'categories' | 'tags' | 'toptags')[]} menu
|
|
54
47
|
* @returns {NavPage[]}
|
|
55
48
|
*/
|
|
56
|
-
footer(currentUrl: URL, _: TranslationProvider, translations: any, subfolder: string, menu: (
|
|
49
|
+
footer(currentUrl: URL, _: TranslationProvider, translations: any, subfolder: string, menu: (MenuItem | 'categories' | 'tags' | 'toptags')[]): NavPage[];
|
|
57
50
|
/**
|
|
58
51
|
*
|
|
59
52
|
* @param {TaxonomyLinks} links
|
|
@@ -115,3 +108,4 @@ export type Taxonomy = import("./taxonomy.mjs").Taxonomy;
|
|
|
115
108
|
export type UrlFormatter = import("./urls.mjs").UrlFormatter;
|
|
116
109
|
export type MarkdownInstance = import("../../types/Astro").MarkdownInstance;
|
|
117
110
|
export type NavPage = import("../../types/NavPage").NavPage;
|
|
111
|
+
export type MenuItem = import("../../types/NavPage").MenuItem;
|
package/lib/v1/navigation.mjs
CHANGED
|
@@ -6,8 +6,17 @@ import * as PostFiltering from '../postFiltering.mjs';
|
|
|
6
6
|
* @typedef { import("./urls.mjs").UrlFormatter } UrlFormatter
|
|
7
7
|
* @typedef { import("../../types/Astro").MarkdownInstance } MarkdownInstance
|
|
8
8
|
* @typedef { import("../../types/NavPage").NavPage } NavPage
|
|
9
|
+
* @typedef { import("../../types/NavPage").MenuItem } MenuItem
|
|
9
10
|
*/
|
|
10
11
|
|
|
12
|
+
const defaults = {
|
|
13
|
+
url: '',
|
|
14
|
+
ariaCurrent: false,
|
|
15
|
+
isOpen: false,
|
|
16
|
+
section: '',
|
|
17
|
+
children: []
|
|
18
|
+
}
|
|
19
|
+
|
|
11
20
|
export class Navigation {
|
|
12
21
|
/**
|
|
13
22
|
* Constructor
|
|
@@ -64,7 +73,7 @@ export class Navigation {
|
|
|
64
73
|
*
|
|
65
74
|
* @param {URL} currentUrl
|
|
66
75
|
* @param {string} subfolder
|
|
67
|
-
* @param {(
|
|
76
|
+
* @param {(MenuItem | 'auto')[]} menu
|
|
68
77
|
* @returns {NavPage[]}
|
|
69
78
|
*/
|
|
70
79
|
menu(currentUrl, subfolder, menu) {
|
|
@@ -72,7 +81,7 @@ export class Navigation {
|
|
|
72
81
|
for (let i = 0; i < menu.length; i++) {
|
|
73
82
|
const item = menu[i];
|
|
74
83
|
if (this.isNavPage(item)) {
|
|
75
|
-
pages.push(item);
|
|
84
|
+
pages.push({ ...defaults, ...item });
|
|
76
85
|
} else {
|
|
77
86
|
const p = this.autoMenu(subfolder);
|
|
78
87
|
for (let j = 0; j < p.length; j++) {
|
|
@@ -155,7 +164,7 @@ export class Navigation {
|
|
|
155
164
|
* @param {TranslationProvider} _
|
|
156
165
|
* @param {any} translations
|
|
157
166
|
* @param {string} subfolder
|
|
158
|
-
* @param {(
|
|
167
|
+
* @param {(MenuItem | 'categories' | 'tags' | 'toptags')[]} menu
|
|
159
168
|
* @returns {NavPage[]}
|
|
160
169
|
*/
|
|
161
170
|
footer(currentUrl, _, translations, subfolder, menu) {
|
|
@@ -174,7 +183,7 @@ export class Navigation {
|
|
|
174
183
|
for (let i = 0; i < menu.length; i++) {
|
|
175
184
|
const item = menu[i];
|
|
176
185
|
if (this.isNavPage(item)) {
|
|
177
|
-
pages.push(item);
|
|
186
|
+
pages.push({ ...defaults, ...item });
|
|
178
187
|
} else {
|
|
179
188
|
switch (item) {
|
|
180
189
|
case 'tags':
|
package/package.json
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro-accelerator-utils",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.40",
|
|
4
4
|
"description": "Astro utilities for Astro Accelerator.",
|
|
5
5
|
"main": "index.mjs",
|
|
6
6
|
"type": "module",
|
|
7
|
+
"packageManager": "pnpm@8.7.0",
|
|
7
8
|
"files": [
|
|
8
9
|
"index.mjs",
|
|
9
10
|
"index.d.mts",
|
package/types/NavPage.d.ts
CHANGED
|
@@ -9,3 +9,14 @@ export interface NavPage {
|
|
|
9
9
|
children: NavPage[];
|
|
10
10
|
rel?: string;
|
|
11
11
|
}
|
|
12
|
+
export interface MenuItem {
|
|
13
|
+
title: string;
|
|
14
|
+
order: number;
|
|
15
|
+
isOpen?: boolean;
|
|
16
|
+
ariaCurrent?: 'page' | false;
|
|
17
|
+
fullTitle?: string;
|
|
18
|
+
children?: NavPage[];
|
|
19
|
+
section?: string;
|
|
20
|
+
url?: string;
|
|
21
|
+
rel?: string;
|
|
22
|
+
}
|