astro-accelerator-utils 0.0.36 → 0.0.37

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 CHANGED
@@ -4,8 +4,9 @@ import * as PostOrdering from "./lib/postOrdering.mjs";
4
4
  import * as PostPaging from "./lib/postPaging.mjs";
5
5
  import * as Cache from "./lib/cache.mjs";
6
6
  import * as Dates from "./lib/dates.mjs";
7
+ import * as FooterMenu from "./lib/footerMenu.mjs";
7
8
  import * as Markdown from "./lib/markdown.mjs";
8
9
  import * as Navigation from "./lib/navigation.mjs";
9
10
  import * as Taxonomy from "./lib/taxonomy.mjs";
10
11
  import * as Urls from "./lib/urls.mjs";
11
- export { PostQueries, PostFiltering, PostOrdering, PostPaging, Cache, Dates, Markdown, Navigation, Taxonomy, Urls };
12
+ export { PostQueries, PostFiltering, PostOrdering, PostPaging, Cache, Dates, FooterMenu, Markdown, Navigation, Taxonomy, Urls };
package/index.mjs CHANGED
@@ -4,6 +4,7 @@ import * as PostOrdering from './lib/postOrdering.mjs';
4
4
  import * as PostPaging from './lib/postPaging.mjs';
5
5
  import * as Cache from './lib/cache.mjs';
6
6
  import * as Dates from './lib/dates.mjs';
7
+ import * as FooterMenu from './lib/footerMenu.mjs';
7
8
  import * as Markdown from './lib/markdown.mjs';
8
9
  import * as Navigation from './lib/navigation.mjs';
9
10
  import * as Taxonomy from './lib/taxonomy.mjs';
@@ -16,6 +17,7 @@ export {
16
17
  PostPaging,
17
18
  Cache,
18
19
  Dates,
20
+ FooterMenu,
19
21
  Markdown,
20
22
  Navigation,
21
23
  Taxonomy,
@@ -0,0 +1,49 @@
1
+ /**
2
+ * @typedef { import("../types/NavPage").NavPage } NavPage
3
+ * @typedef { import("../types/Astro").Site } Site
4
+ * @typedef { import("../types/Translations").Entry } Entry
5
+ * @typedef { import("../types/Translations").TranslationProvider } TranslationProvider
6
+ * @typedef { import("../types/Taxonomy").TaxonomyLinks } TaxonomyLinks
7
+ */
8
+ /**
9
+ *
10
+ * @param {URL} currentUrl
11
+ * @param {TranslationProvider} _
12
+ * @param {any} translations
13
+ * @param {Site} site
14
+ * @param {(NavPage | 'categories' | 'tags' | 'toptags')[]} menu
15
+ * @returns
16
+ */
17
+ export function getMenu(currentUrl: URL, _: TranslationProvider, translations: any, site: any, menu: (NavPage | 'categories' | 'tags' | 'toptags')[]): Promise<import("../types/NavPage").NavPage[]>;
18
+ /**
19
+ *
20
+ * @param {TaxonomyLinks} links
21
+ * @param {TranslationProvider} _
22
+ * @param {any} translations
23
+ * @param {Site} site
24
+ * @returns {NavPage[]}
25
+ */
26
+ export function getCategories(links: TaxonomyLinks, _: TranslationProvider, translations: any, site: any): NavPage[];
27
+ /**
28
+ *
29
+ * @param {TaxonomyLinks} links
30
+ * @param {TranslationProvider} _
31
+ * @param {any} translations
32
+ * @param {Site} site
33
+ * @returns {NavPage[]}
34
+ */
35
+ export function getTags(links: TaxonomyLinks, _: TranslationProvider, translations: any, site: any): NavPage[];
36
+ /**
37
+ *
38
+ * @param {TaxonomyLinks} links
39
+ * @param {TranslationProvider} _
40
+ * @param {any} translations
41
+ * @param {Site} site
42
+ * @returns {NavPage[]}
43
+ */
44
+ export function getTopTags(links: TaxonomyLinks, _: TranslationProvider, translations: any, site: any): NavPage[];
45
+ export type NavPage = import("../types/NavPage").NavPage;
46
+ export type Site = import("../types/Astro").Site;
47
+ export type Entry = import("../types/Translations").Entry;
48
+ export type TranslationProvider = import("../types/Translations").TranslationProvider;
49
+ export type TaxonomyLinks = import("../types/Taxonomy").TaxonomyLinks;
@@ -0,0 +1,175 @@
1
+ /**
2
+ * @typedef { import("../types/NavPage").NavPage } NavPage
3
+ * @typedef { import("../types/Astro").Site } Site
4
+ * @typedef { import("../types/Translations").Entry } Entry
5
+ * @typedef { import("../types/Translations").TranslationProvider } TranslationProvider
6
+ * @typedef { import("../types/Taxonomy").TaxonomyLinks } TaxonomyLinks
7
+ */
8
+
9
+ /**
10
+ *
11
+ * @param {URL} currentUrl
12
+ * @param {TranslationProvider} _
13
+ * @param {any} translations
14
+ * @param {Site} site
15
+ * @param {(NavPage | 'categories' | 'tags' | 'toptags')[]} menu
16
+ * @returns
17
+ */
18
+ export async function getMenu (currentUrl, _, translations, site, menu) {
19
+ const links = Taxonomy.taxonomyLinks(translations, _, site);
20
+
21
+ /** @type {NavPage[]} */
22
+ let pages = [];
23
+
24
+ for (let i = 0; i < menu.length; i++) {
25
+ const item = menu[i];
26
+ if (Navigation.isNavPage(item)) {
27
+ pages.push(item);
28
+ } else {
29
+ switch (item) {
30
+ case 'tags':
31
+ const tags = await getTags(links, _, translations, site);
32
+ for (let j = 0; j < tags.length; j++) {
33
+ pages.push(tags[j]);
34
+ }
35
+ break;
36
+ case 'toptags':
37
+ const toptags = await getTopTags(links, _, translations, site);
38
+ for (let j = 0; j < toptags.length; j++) {
39
+ pages.push(toptags[j]);
40
+ }
41
+ break;
42
+ case 'categories':
43
+ const categories = await getCategories(links, _, translations, site);
44
+ for (let j = 0; j < categories.length; j++) {
45
+ pages.push(categories[j]);
46
+ }
47
+ break;
48
+ }
49
+ }
50
+ }
51
+
52
+ PostQueries.setCurrentPage(pages, currentUrl);
53
+
54
+ return pages;
55
+ }
56
+
57
+ /**
58
+ *
59
+ * @param {TaxonomyLinks} links
60
+ * @param {TranslationProvider} _
61
+ * @param {any} translations
62
+ * @param {Site} site
63
+ * @returns {NavPage[]}
64
+ */
65
+ export async function getCategories (links, _, translations, site) {
66
+
67
+ const category = _(translations.articles.category) ?? 'category';
68
+ const categoryTitle = _(translations.articles.category_title) ?? 'Categories';
69
+ const categoryLink = `${site.subfolder}/${category}/`;
70
+
71
+ let order = 0;
72
+
73
+ const taxonomy = await Taxonomy.getTaxonomy();
74
+
75
+ /** @type {NavPage[]} */
76
+ const pageHierarchy = [{
77
+ title: categoryTitle,
78
+ url: categoryLink,
79
+ ariaCurrent: false,
80
+ isOpen: false,
81
+ order: 1,
82
+ children: taxonomy.categories.map(item => {
83
+ return {
84
+ title: item.title,
85
+ url: links.getCategoryLink(item.title),
86
+ ariaCurrent: false,
87
+ isOpen: false,
88
+ order: ++order,
89
+ children: []
90
+ };
91
+ })
92
+ }];
93
+
94
+ return pageHierarchy;
95
+ }
96
+
97
+ /**
98
+ *
99
+ * @param {TaxonomyLinks} links
100
+ * @param {TranslationProvider} _
101
+ * @param {any} translations
102
+ * @param {Site} site
103
+ * @returns {NavPage[]}
104
+ */
105
+ export async function getTags (links, _, translations, site) {
106
+
107
+ const tag = _(translations.articles.tag) ?? 'tag';
108
+ const tagTitle = _(translations.articles.tag_title) ?? 'Tags';
109
+ const tagLink = `${site.subfolder}/${tag}/`;
110
+
111
+ let order = 0;
112
+
113
+ const taxonomy = await Taxonomy.getTaxonomy();
114
+
115
+ /** @type {NavPage[]} */
116
+ const pageHierarchy = [{
117
+ title: tagTitle,
118
+ url: tagLink,
119
+ ariaCurrent: false,
120
+ isOpen: false,
121
+ order: 1,
122
+ children: taxonomy.tags.map(item => {
123
+ return {
124
+ title: item.title,
125
+ url: links.getTagLink(item.title),
126
+ ariaCurrent: false,
127
+ isOpen: false,
128
+ order: ++order,
129
+ children: []
130
+ };
131
+ })
132
+ }];
133
+
134
+ return pageHierarchy;
135
+ }
136
+
137
+ /**
138
+ *
139
+ * @param {TaxonomyLinks} links
140
+ * @param {TranslationProvider} _
141
+ * @param {any} translations
142
+ * @param {Site} site
143
+ * @returns {NavPage[]}
144
+ */
145
+ export async function getTopTags (links, _, translations, site) {
146
+
147
+ const tag = _(translations.articles.tag) ?? 'tag';
148
+ const tagTitle = _(translations.articles.tag_title) ?? 'Tags';
149
+ const tagLink = `${site.subfolder}/${tag}/`;
150
+
151
+ let order = 0;
152
+
153
+ const taxonomy = await Taxonomy.getTaxonomy();
154
+
155
+ /** @type {NavPage[]} */
156
+ const pageHierarchy = [{
157
+ title: tagTitle,
158
+ url: tagLink,
159
+ ariaCurrent: false,
160
+ isOpen: false,
161
+ order: 1,
162
+ children: taxonomy.topTags.map(item => {
163
+ return {
164
+ title: item.title,
165
+ url: links.getTagLink(item.title),
166
+ ariaCurrent: false,
167
+ isOpen: false,
168
+ order: ++order,
169
+ children: []
170
+ };
171
+ })
172
+ }];
173
+
174
+ return pageHierarchy;
175
+ }
@@ -6,9 +6,10 @@
6
6
  *
7
7
  * @param {URL} currentUrl
8
8
  * @param {Site} site
9
+ * @param {NavPage | 'auto'} menu
9
10
  * @returns {Promise<NavPage[]}
10
11
  */
11
- export function getMenu(currentUrl: URL, site: Site): Promise<NavPage[]>;
12
+ export function getMenu(currentUrl: URL, site: Site, menu: NavPage | 'auto'): Promise<NavPage[]>;
12
13
  /**
13
14
  *
14
15
  * @param {NavPage | 'auto' | 'tags' | 'toptags' | 'categories'} item
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro-accelerator-utils",
3
- "version": "0.0.36",
3
+ "version": "0.0.37",
4
4
  "description": "Astro utilities for Astro Accelerator.",
5
5
  "main": "index.mjs",
6
6
  "files": [
@@ -0,0 +1,6 @@
1
+ export interface Entry {
2
+ [key: string]: string;
3
+ }
4
+ export interface TranslationProvider {
5
+ (entry: Entry): string;
6
+ }