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.
@@ -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
@@ -1,6 +1,6 @@
1
- import { getItem, setItem } from './cache.mjs';
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 = await getItem(key);
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
- await setItem(key, allPages);
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 = await getItem(key);
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
- await setItem(key, allPages);
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 = await getItem(cacheKey);
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
- await setItem(cacheKey, authorInfo);
143
+ cache.setItem(cacheKey, authorInfo);
150
144
  }
151
145
 
152
146
  return authorInfo;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro-accelerator-utils",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "Astro utilities for Astro Accelerator.",
5
5
  "main": "index.mjs",
6
6
  "type": "module",
package/types/Site.d.ts CHANGED
@@ -21,6 +21,7 @@ export type Site = {
21
21
  pageSize: number;
22
22
  pageLinks: number;
23
23
  rssLimit: number;
24
+ cacheMaxAge: number;
24
25
  featureFlags: {
25
26
  codeBlocks: 'copy'[];
26
27
  figures: 'enlarge'[];