astro-accelerator-utils 0.0.30 → 0.0.31
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/postFiltering.d.mts +11 -11
- package/lib/postFiltering.mjs +5 -5
- package/lib/postOrdering.d.mts +10 -10
- package/lib/postOrdering.mjs +6 -6
- package/lib/postQueries.d.mts +16 -9
- package/lib/postQueries.mjs +34 -5
- package/package.json +1 -1
- package/types/Astro.d.ts +3 -2
- package/types/AuthorInfo.d.ts +4 -0
- package/types/AuthorList.d.ts +3 -3
- package/types/PagePredicate.d.ts +1 -1
package/lib/postFiltering.d.mts
CHANGED
|
@@ -4,34 +4,34 @@
|
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
6
6
|
* Predicate for whether a page should appear in the sitemap
|
|
7
|
-
* @param {MarkdownInstance
|
|
7
|
+
* @param {MarkdownInstance} p
|
|
8
8
|
* @returns {boolean}
|
|
9
9
|
*/
|
|
10
|
-
export function showInSitemap(p:
|
|
10
|
+
export function showInSitemap(p: MarkdownInstance): boolean;
|
|
11
11
|
/**
|
|
12
12
|
* Predicate for whether a page should appear in the site search
|
|
13
|
-
* @param {MarkdownInstance
|
|
13
|
+
* @param {MarkdownInstance} p
|
|
14
14
|
* @returns {boolean}
|
|
15
15
|
*/
|
|
16
|
-
export function showInSearch(p:
|
|
16
|
+
export function showInSearch(p: MarkdownInstance): boolean;
|
|
17
17
|
/**
|
|
18
18
|
* Predicate for whether a page should appear in the navigation menu
|
|
19
|
-
* @param {MarkdownInstance
|
|
19
|
+
* @param {MarkdownInstance} p
|
|
20
20
|
* @returns {boolean}
|
|
21
21
|
*/
|
|
22
|
-
export function showInMenu(p:
|
|
22
|
+
export function showInMenu(p: MarkdownInstance): boolean;
|
|
23
23
|
/**
|
|
24
24
|
* Predicate for whether a page is an author page
|
|
25
|
-
* @param {MarkdownInstance
|
|
25
|
+
* @param {MarkdownInstance} p
|
|
26
26
|
* @returns {boolean}
|
|
27
27
|
*/
|
|
28
|
-
export function isAuthor(p:
|
|
28
|
+
export function isAuthor(p: MarkdownInstance): boolean;
|
|
29
29
|
/**
|
|
30
30
|
* Predicate for whether a page is a search page
|
|
31
|
-
* @param {MarkdownInstance
|
|
31
|
+
* @param {MarkdownInstance} p
|
|
32
32
|
* @returns {boolean}
|
|
33
33
|
*/
|
|
34
|
-
export function isSearch(p:
|
|
34
|
+
export function isSearch(p: MarkdownInstance): boolean;
|
|
35
35
|
/**
|
|
36
36
|
* Predicate for whether a page should be listed
|
|
37
37
|
* @param {MarkdownInstance<Record<string, any>>} p
|
|
@@ -39,4 +39,4 @@ export function isSearch(p: any): boolean;
|
|
|
39
39
|
*/
|
|
40
40
|
export function isListable(p: any): boolean;
|
|
41
41
|
export type PagePredicate = import("../types/PagePredicate").PagePredicate;
|
|
42
|
-
export type MarkdownInstance =
|
|
42
|
+
export type MarkdownInstance = import("../types/Astro").MarkdownInstance;
|
package/lib/postFiltering.mjs
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Predicate for whether a page should appear in the sitemap
|
|
8
|
-
* @param {MarkdownInstance
|
|
8
|
+
* @param {MarkdownInstance} p
|
|
9
9
|
* @returns {boolean}
|
|
10
10
|
*/
|
|
11
11
|
export function showInSitemap (p) {
|
|
@@ -20,7 +20,7 @@ export function showInSitemap (p) {
|
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
22
|
* Predicate for whether a page should appear in the site search
|
|
23
|
-
* @param {MarkdownInstance
|
|
23
|
+
* @param {MarkdownInstance} p
|
|
24
24
|
* @returns {boolean}
|
|
25
25
|
*/
|
|
26
26
|
export function showInSearch (p) {
|
|
@@ -35,7 +35,7 @@ export function showInSearch (p) {
|
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
37
|
* Predicate for whether a page should appear in the navigation menu
|
|
38
|
-
* @param {MarkdownInstance
|
|
38
|
+
* @param {MarkdownInstance} p
|
|
39
39
|
* @returns {boolean}
|
|
40
40
|
*/
|
|
41
41
|
export function showInMenu (p) {
|
|
@@ -49,7 +49,7 @@ export function showInMenu (p) {
|
|
|
49
49
|
|
|
50
50
|
/**
|
|
51
51
|
* Predicate for whether a page is an author page
|
|
52
|
-
* @param {MarkdownInstance
|
|
52
|
+
* @param {MarkdownInstance} p
|
|
53
53
|
* @returns {boolean}
|
|
54
54
|
*/
|
|
55
55
|
export function isAuthor (p) {
|
|
@@ -62,7 +62,7 @@ export function isAuthor (p) {
|
|
|
62
62
|
|
|
63
63
|
/**
|
|
64
64
|
* Predicate for whether a page is a search page
|
|
65
|
-
* @param {MarkdownInstance
|
|
65
|
+
* @param {MarkdownInstance} p
|
|
66
66
|
* @returns {boolean}
|
|
67
67
|
*/
|
|
68
68
|
export function isSearch (p) {
|
package/lib/postOrdering.d.mts
CHANGED
|
@@ -3,23 +3,23 @@
|
|
|
3
3
|
*/
|
|
4
4
|
/**
|
|
5
5
|
* Sorts by the pubDate field
|
|
6
|
-
* @param {MarkdownInstance
|
|
7
|
-
* @param {MarkdownInstance
|
|
6
|
+
* @param {MarkdownInstance} a
|
|
7
|
+
* @param {MarkdownInstance} b
|
|
8
8
|
* @returns {any}
|
|
9
9
|
*/
|
|
10
|
-
export function sortByPubDate(a:
|
|
10
|
+
export function sortByPubDate(a: MarkdownInstance, b: MarkdownInstance): any;
|
|
11
11
|
/**
|
|
12
12
|
* Sorts by the pubDate field in descending order
|
|
13
|
-
* @param {MarkdownInstance
|
|
14
|
-
* @param {MarkdownInstance
|
|
13
|
+
* @param {MarkdownInstance} a
|
|
14
|
+
* @param {MarkdownInstance} b
|
|
15
15
|
* @returns {any}
|
|
16
16
|
*/
|
|
17
|
-
export function sortByPubDateDesc(a:
|
|
17
|
+
export function sortByPubDateDesc(a: MarkdownInstance, b: MarkdownInstance): any;
|
|
18
18
|
/**
|
|
19
19
|
* Sorts by the modDate field
|
|
20
|
-
* @param {MarkdownInstance
|
|
21
|
-
* @param {MarkdownInstance
|
|
20
|
+
* @param {MarkdownInstance} a
|
|
21
|
+
* @param {MarkdownInstance} b
|
|
22
22
|
* @returns {any}
|
|
23
23
|
*/
|
|
24
|
-
export function sortByModDate(a:
|
|
25
|
-
export type MarkdownInstance =
|
|
24
|
+
export function sortByModDate(a: MarkdownInstance, b: MarkdownInstance): any;
|
|
25
|
+
export type MarkdownInstance = import("../types/Astro").MarkdownInstance;
|
package/lib/postOrdering.mjs
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Sorts by the pubDate field
|
|
7
|
-
* @param {MarkdownInstance
|
|
8
|
-
* @param {MarkdownInstance
|
|
7
|
+
* @param {MarkdownInstance} a
|
|
8
|
+
* @param {MarkdownInstance} b
|
|
9
9
|
* @returns {any}
|
|
10
10
|
*/
|
|
11
11
|
export function sortByPubDate (a, b) {
|
|
@@ -14,8 +14,8 @@ export function sortByPubDate (a, b) {
|
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* Sorts by the pubDate field in descending order
|
|
17
|
-
* @param {MarkdownInstance
|
|
18
|
-
* @param {MarkdownInstance
|
|
17
|
+
* @param {MarkdownInstance} a
|
|
18
|
+
* @param {MarkdownInstance} b
|
|
19
19
|
* @returns {any}
|
|
20
20
|
*/
|
|
21
21
|
export function sortByPubDateDesc (a, b) {
|
|
@@ -24,8 +24,8 @@ export function sortByPubDateDesc (a, b) {
|
|
|
24
24
|
|
|
25
25
|
/**
|
|
26
26
|
* Sorts by the modDate field
|
|
27
|
-
* @param {MarkdownInstance
|
|
28
|
-
* @param {MarkdownInstance
|
|
27
|
+
* @param {MarkdownInstance} a
|
|
28
|
+
* @param {MarkdownInstance} b
|
|
29
29
|
* @returns {any}
|
|
30
30
|
*/
|
|
31
31
|
export function sortByModDate (a, b) {
|
package/lib/postQueries.d.mts
CHANGED
|
@@ -1,22 +1,28 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Fetches pages
|
|
3
3
|
* @param {PagePredicate} [filter]
|
|
4
|
-
* @returns {Promise<MarkdownInstance
|
|
4
|
+
* @returns {Promise<MarkdownInstance}
|
|
5
5
|
*/
|
|
6
|
-
export function getPages(filter?: PagePredicate): Promise<MarkdownInstance
|
|
6
|
+
export function getPages(filter?: PagePredicate): Promise<MarkdownInstance>;
|
|
7
7
|
/**
|
|
8
8
|
*
|
|
9
9
|
* @param {Site} site
|
|
10
10
|
* @param {PagePredicate} [filter]
|
|
11
|
-
* @returns {Promise<MarkdownInstance
|
|
11
|
+
* @returns {Promise<MarkdownInstance[]>}
|
|
12
12
|
*/
|
|
13
|
-
export function getTopLevelPages(site: Site, filter?: PagePredicate): Promise<MarkdownInstance
|
|
13
|
+
export function getTopLevelPages(site: Site, filter?: PagePredicate): Promise<MarkdownInstance[]>;
|
|
14
14
|
/**
|
|
15
15
|
* Gets a list of authors, and exposes main author and contributors
|
|
16
16
|
* @param {Frontmatter} frontmatter
|
|
17
17
|
* @returns {Promise<AuthorList>}
|
|
18
18
|
*/
|
|
19
19
|
export function getAuthors(frontmatter: Frontmatter): Promise<AuthorList>;
|
|
20
|
+
/**
|
|
21
|
+
*
|
|
22
|
+
* @param {string} slug
|
|
23
|
+
* @returns {Promise<AuthorInfo>}
|
|
24
|
+
*/
|
|
25
|
+
export function getAuthorInfo(slug: string): Promise<AuthorInfo>;
|
|
20
26
|
/**
|
|
21
27
|
* Returns a list of breadcrumbs
|
|
22
28
|
* @param {URL} currentUrl
|
|
@@ -26,11 +32,11 @@ export function getAuthors(frontmatter: Frontmatter): Promise<AuthorList>;
|
|
|
26
32
|
export function getBreadcrumbs(currentUrl: URL, site: Site): NavPage[];
|
|
27
33
|
/**
|
|
28
34
|
* Converts a MarkdownInstance into a NavPage
|
|
29
|
-
* @param {MarkdownInstance
|
|
35
|
+
* @param {MarkdownInstance} page
|
|
30
36
|
* @param {Site}
|
|
31
37
|
* @returns {NavPage}
|
|
32
38
|
*/
|
|
33
|
-
export function mapNavPage(page:
|
|
39
|
+
export function mapNavPage(page: MarkdownInstance, site: any): NavPage;
|
|
34
40
|
/**
|
|
35
41
|
* Walks the tree to set current page
|
|
36
42
|
* @param {NavPage[]} pages
|
|
@@ -39,14 +45,15 @@ export function mapNavPage(page: any, site: any): NavPage;
|
|
|
39
45
|
export function setCurrentPage(pages: NavPage[], currentUrl: URL): void;
|
|
40
46
|
/**
|
|
41
47
|
* Pops matching page from array
|
|
42
|
-
* @param {MarkdownInstance
|
|
48
|
+
* @param {MarkdownInstance[]} allPages
|
|
43
49
|
* @param {string} search
|
|
44
50
|
* @returns
|
|
45
51
|
*/
|
|
46
|
-
export function popMatchingPage(allPages: MarkdownInstance
|
|
52
|
+
export function popMatchingPage(allPages: MarkdownInstance[], search: string): import("../types/Astro").MarkdownInstance;
|
|
47
53
|
export type PagePredicate = import("../types/PagePredicate").PagePredicate;
|
|
48
54
|
export type Frontmatter = import("../types/Frontmatter").Frontmatter;
|
|
49
|
-
export type MarkdownInstance =
|
|
55
|
+
export type MarkdownInstance = import("../types/Astro").MarkdownInstance;
|
|
50
56
|
export type AuthorList = import("../types/AuthorList").AuthorList;
|
|
57
|
+
export type AuthorInfo = import("../types/AuthorInfo").AuthorInfo;
|
|
51
58
|
export type NavPage = import("../types/NavPage").NavPage;
|
|
52
59
|
export type Site = import("../types/Site").Site;
|
package/lib/postQueries.mjs
CHANGED
|
@@ -7,6 +7,7 @@ import * as Urls from './urls.mjs';
|
|
|
7
7
|
* @typedef { import("../types/Frontmatter").Frontmatter } Frontmatter
|
|
8
8
|
* @typedef { import("../types/Astro").MarkdownInstance } MarkdownInstance
|
|
9
9
|
* @typedef { import("../types/AuthorList").AuthorList } AuthorList
|
|
10
|
+
* @typedef { import("../types/AuthorInfo").AuthorInfo } AuthorInfo
|
|
10
11
|
* @typedef { import("../types/NavPage").NavPage } NavPage
|
|
11
12
|
* @typedef { import("../types/Site").Site } Site
|
|
12
13
|
*/
|
|
@@ -18,7 +19,7 @@ function fetchAll () {
|
|
|
18
19
|
/**
|
|
19
20
|
* Fetches pages
|
|
20
21
|
* @param {PagePredicate} [filter]
|
|
21
|
-
* @returns {Promise<MarkdownInstance
|
|
22
|
+
* @returns {Promise<MarkdownInstance}
|
|
22
23
|
*/
|
|
23
24
|
export async function getPages (filter) {
|
|
24
25
|
const key = 'PageQueries__getPages';
|
|
@@ -41,12 +42,12 @@ export async function getPages (filter) {
|
|
|
41
42
|
*
|
|
42
43
|
* @param {Site} site
|
|
43
44
|
* @param {PagePredicate} [filter]
|
|
44
|
-
* @returns {Promise<MarkdownInstance
|
|
45
|
+
* @returns {Promise<MarkdownInstance[]>}
|
|
45
46
|
*/
|
|
46
47
|
export async function getTopLevelPages (site, filter) {
|
|
47
48
|
const key = 'PageQueries__getTopLevelPages';
|
|
48
49
|
|
|
49
|
-
/** @type {MarkdownInstance
|
|
50
|
+
/** @type {MarkdownInstance[]} */
|
|
50
51
|
let allPages = await getItem(key);
|
|
51
52
|
|
|
52
53
|
if (allPages == null) {
|
|
@@ -111,6 +112,34 @@ export async function getAuthors (frontmatter) {
|
|
|
111
112
|
return result;
|
|
112
113
|
}
|
|
113
114
|
|
|
115
|
+
/**
|
|
116
|
+
*
|
|
117
|
+
* @param {string} slug
|
|
118
|
+
* @returns {Promise<AuthorInfo>}
|
|
119
|
+
*/
|
|
120
|
+
export async function getAuthorInfo (slug) {
|
|
121
|
+
const cacheKey = 'Global__author_info';
|
|
122
|
+
|
|
123
|
+
/** @type {AuthorInfo} */
|
|
124
|
+
let authorInfo = await getItem(cacheKey);
|
|
125
|
+
|
|
126
|
+
if (authorInfo == null) {
|
|
127
|
+
const allPages = await getPages();
|
|
128
|
+
|
|
129
|
+
const author = allPages
|
|
130
|
+
.filter(PostFiltering.isAuthor)
|
|
131
|
+
.filter(x => x.url?.split('/')[2] == slug)[0];
|
|
132
|
+
|
|
133
|
+
authorInfo = {
|
|
134
|
+
frontmatter: author.frontmatter
|
|
135
|
+
};
|
|
136
|
+
|
|
137
|
+
await setItem(cacheKey, authorInfo);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
return authorInfo;
|
|
141
|
+
}
|
|
142
|
+
|
|
114
143
|
/**
|
|
115
144
|
* Returns a list of breadcrumbs
|
|
116
145
|
* @param {URL} currentUrl
|
|
@@ -142,7 +171,7 @@ export async function getBreadcrumbs (currentUrl, site) {
|
|
|
142
171
|
|
|
143
172
|
/**
|
|
144
173
|
* Converts a MarkdownInstance into a NavPage
|
|
145
|
-
* @param {MarkdownInstance
|
|
174
|
+
* @param {MarkdownInstance} page
|
|
146
175
|
* @param {Site}
|
|
147
176
|
* @returns {NavPage}
|
|
148
177
|
*/
|
|
@@ -194,7 +223,7 @@ export function setCurrentPage (pages, currentUrl) {
|
|
|
194
223
|
|
|
195
224
|
/**
|
|
196
225
|
* Pops matching page from array
|
|
197
|
-
* @param {MarkdownInstance
|
|
226
|
+
* @param {MarkdownInstance[]} allPages
|
|
198
227
|
* @param {string} search
|
|
199
228
|
* @returns
|
|
200
229
|
*/
|
package/package.json
CHANGED
package/types/Astro.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { Frontmatter } from "./Frontmatter";
|
|
2
|
+
export type MarkdownInstance = {
|
|
3
|
+
frontmatter: Frontmatter;
|
|
3
4
|
/** Absolute file path (e.g. `/home/user/projects/.../file.md`) */
|
|
4
5
|
file: string;
|
|
5
6
|
/** Browser URL for files under `/src/pages` (e.g. `/en/guides/markdown-content`) */
|
package/types/AuthorList.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { MarkdownInstance } from "./Astro";
|
|
|
2
2
|
import type { BannerImage } from "./BannerImage";
|
|
3
3
|
export interface AuthorList {
|
|
4
4
|
image: BannerImage | null;
|
|
5
|
-
writers: MarkdownInstance
|
|
6
|
-
mainAuthor: MarkdownInstance
|
|
7
|
-
contributors: MarkdownInstance
|
|
5
|
+
writers: MarkdownInstance[];
|
|
6
|
+
mainAuthor: MarkdownInstance | null;
|
|
7
|
+
contributors: MarkdownInstance[];
|
|
8
8
|
}
|
package/types/PagePredicate.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { MarkdownInstance } from "./Astro";
|
|
2
|
-
export type PagePredicate = (value: MarkdownInstance
|
|
2
|
+
export type PagePredicate = (value: MarkdownInstance, index: number, array: MarkdownInstance[]) => boolean;
|