astro-accelerator-utils 0.1.6 → 0.1.7
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/postQueries.d.mts +0 -5
- package/lib/postQueries.mjs +9 -15
- package/package.json +1 -1
- package/types/Site.d.ts +1 -0
package/lib/postQueries.d.mts
CHANGED
|
@@ -1,8 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Replaces the import.meta.glob function
|
|
3
|
-
* @param {() => MarkdownInstance[]} fetcher
|
|
4
|
-
*/
|
|
5
|
-
export function injectFetchAll(fetcher: () => MarkdownInstance[]): void;
|
|
6
1
|
/**
|
|
7
2
|
* Replaced by Posts.all()
|
|
8
3
|
* @deprecated Use Posts.all().filter(...) to filter results
|
package/lib/postQueries.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import * as PostFiltering from './postFiltering.mjs';
|
|
1
|
+
import { Cache } from './v1/cache.mjs';
|
|
3
2
|
import { UrlFormatter } from './v1/urls.mjs';
|
|
3
|
+
import * as PostFiltering from './postFiltering.mjs';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* @typedef { import("../types/PagePredicate").PagePredicate } PagePredicate
|
|
@@ -18,13 +18,7 @@ let fetchAll = () => {
|
|
|
18
18
|
return import.meta.glob("/src/pages/**/*.md", { eager: true });
|
|
19
19
|
}
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
* Replaces the import.meta.glob function
|
|
23
|
-
* @param {() => MarkdownInstance[]} fetcher
|
|
24
|
-
*/
|
|
25
|
-
export function injectFetchAll (fetcher) {
|
|
26
|
-
fetchAll = fetcher;
|
|
27
|
-
}
|
|
21
|
+
const cache = new Cache(200);
|
|
28
22
|
|
|
29
23
|
/**
|
|
30
24
|
* Replaced by Posts.all()
|
|
@@ -34,12 +28,12 @@ export function injectFetchAll (fetcher) {
|
|
|
34
28
|
*/
|
|
35
29
|
export async function getPages (filter) {
|
|
36
30
|
const key = 'PageQueries__getPages';
|
|
37
|
-
let allPages =
|
|
31
|
+
let allPages = cache.getItem(key);
|
|
38
32
|
|
|
39
33
|
if (allPages == null) {
|
|
40
34
|
const pageImportResult = fetchAll();
|
|
41
35
|
allPages = Object.values(pageImportResult);
|
|
42
|
-
|
|
36
|
+
cache.setItem(key, allPages);
|
|
43
37
|
}
|
|
44
38
|
|
|
45
39
|
if (filter == null) {
|
|
@@ -60,7 +54,7 @@ export async function getTopLevelPages (site, filter) {
|
|
|
60
54
|
const key = 'PageQueries__getTopLevelPages';
|
|
61
55
|
|
|
62
56
|
/** @type {MarkdownInstance[]} */
|
|
63
|
-
let allPages =
|
|
57
|
+
let allPages = cache.getItem(key);
|
|
64
58
|
|
|
65
59
|
if (allPages == null) {
|
|
66
60
|
allPages = await getPages();
|
|
@@ -73,7 +67,7 @@ export async function getTopLevelPages (site, filter) {
|
|
|
73
67
|
|| (depth == (expectedDepth - 1) && p.file.includes(site.subfolder.toLowerCase() + '.md'));
|
|
74
68
|
});
|
|
75
69
|
|
|
76
|
-
|
|
70
|
+
cache.setItem(key, allPages);
|
|
77
71
|
}
|
|
78
72
|
|
|
79
73
|
if (filter == null) {
|
|
@@ -133,7 +127,7 @@ export async function getAuthorInfo (slug) {
|
|
|
133
127
|
const cacheKey = 'Global__author_info';
|
|
134
128
|
|
|
135
129
|
/** @type {AuthorInfo} */
|
|
136
|
-
let authorInfo =
|
|
130
|
+
let authorInfo = cache.getItem(cacheKey);
|
|
137
131
|
|
|
138
132
|
if (authorInfo == null) {
|
|
139
133
|
const allPages = await getPages();
|
|
@@ -146,7 +140,7 @@ export async function getAuthorInfo (slug) {
|
|
|
146
140
|
frontmatter: author.frontmatter
|
|
147
141
|
};
|
|
148
142
|
|
|
149
|
-
|
|
143
|
+
cache.setItem(cacheKey, authorInfo);
|
|
150
144
|
}
|
|
151
145
|
|
|
152
146
|
return authorInfo;
|
package/package.json
CHANGED