astro-accelerator-utils 0.0.7 → 0.0.9
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/dist/lib/Cache.js +25 -42
- package/dist/lib/postFiltering.js +0 -2
- package/dist/lib/postQueries.js +12 -23
- package/package.json +1 -1
package/dist/lib/Cache.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
4
|
};
|
|
@@ -16,45 +7,37 @@ exports.setItem = exports.getItem = exports.getItemPath = exports.getCachePath =
|
|
|
16
7
|
const fs_1 = __importDefault(require("fs"));
|
|
17
8
|
const path_1 = __importDefault(require("path"));
|
|
18
9
|
const process_1 = __importDefault(require("process"));
|
|
19
|
-
exports.maxAge = 200;
|
|
20
|
-
function getCachePath() {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return cachePath;
|
|
25
|
-
});
|
|
10
|
+
exports.maxAge = 200;
|
|
11
|
+
async function getCachePath() {
|
|
12
|
+
const cachePath = path_1.default.join(process_1.default.cwd(), '.cache/');
|
|
13
|
+
await fs_1.default.promises.mkdir(cachePath, { recursive: true });
|
|
14
|
+
return cachePath;
|
|
26
15
|
}
|
|
27
16
|
exports.getCachePath = getCachePath;
|
|
28
|
-
function getItemPath(key) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
return path_1.default.join(cachePath, key + '.cache');
|
|
32
|
-
});
|
|
17
|
+
async function getItemPath(key) {
|
|
18
|
+
const cachePath = await getCachePath();
|
|
19
|
+
return path_1.default.join(cachePath, key + '.cache');
|
|
33
20
|
}
|
|
34
21
|
exports.getItemPath = getItemPath;
|
|
35
|
-
function getItem(key) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
return JSON.parse(content);
|
|
46
|
-
}
|
|
22
|
+
async function getItem(key) {
|
|
23
|
+
const itemPath = await getItemPath(key);
|
|
24
|
+
try {
|
|
25
|
+
const { mtime } = await fs_1.default.promises.stat(itemPath);
|
|
26
|
+
var date_time = new Date();
|
|
27
|
+
let timeDifference = Math.abs((date_time.getTime() - mtime.getTime()) / 1000);
|
|
28
|
+
if (timeDifference < exports.maxAge) {
|
|
29
|
+
console.log('Cache hit', key);
|
|
30
|
+
const content = fs_1.default.readFileSync(itemPath).toString();
|
|
31
|
+
return JSON.parse(content);
|
|
47
32
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
33
|
+
}
|
|
34
|
+
catch { }
|
|
35
|
+
console.warn('Cache miss', key);
|
|
36
|
+
return null;
|
|
52
37
|
}
|
|
53
38
|
exports.getItem = getItem;
|
|
54
|
-
function setItem(key, value) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
yield fs_1.default.promises.writeFile(itemPath, JSON.stringify(value));
|
|
58
|
-
});
|
|
39
|
+
async function setItem(key, value) {
|
|
40
|
+
const itemPath = await getItemPath(key);
|
|
41
|
+
await fs_1.default.promises.writeFile(itemPath, JSON.stringify(value));
|
|
59
42
|
}
|
|
60
43
|
exports.setItem = setItem;
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.isListable = exports.isSearch = exports.isAuthor = exports.showInMenu = exports.showInSearch = exports.showInSitemap = void 0;
|
|
4
4
|
function showInSitemap(p) {
|
|
5
|
-
// User setting to remove from sitemap
|
|
6
5
|
if (typeof p.frontmatter.navSitemap !== 'undefined'
|
|
7
6
|
&& p.frontmatter.navSitemap == false) {
|
|
8
7
|
return false;
|
|
@@ -11,7 +10,6 @@ function showInSitemap(p) {
|
|
|
11
10
|
}
|
|
12
11
|
exports.showInSitemap = showInSitemap;
|
|
13
12
|
function showInSearch(p) {
|
|
14
|
-
// User setting to remove from search
|
|
15
13
|
if (typeof p.frontmatter.navSearch !== 'undefined'
|
|
16
14
|
&& p.frontmatter.navSearch == false) {
|
|
17
15
|
return false;
|
package/dist/lib/postQueries.js
CHANGED
|
@@ -1,29 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.getPages = void 0;
|
|
13
4
|
const Cache_1 = require("./Cache");
|
|
14
|
-
function getPages(fetchPages, filter) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return allPages.filter(filter);
|
|
27
|
-
});
|
|
5
|
+
async function getPages(fetchPages, filter) {
|
|
6
|
+
const key = 'PageQueries__getPages';
|
|
7
|
+
let allPages = await (0, Cache_1.getItem)(key);
|
|
8
|
+
if (allPages == null) {
|
|
9
|
+
const pageImportResult = fetchPages();
|
|
10
|
+
allPages = Object.values(pageImportResult);
|
|
11
|
+
await (0, Cache_1.setItem)(key, allPages);
|
|
12
|
+
}
|
|
13
|
+
if (filter == null) {
|
|
14
|
+
return allPages;
|
|
15
|
+
}
|
|
16
|
+
return allPages.filter(filter);
|
|
28
17
|
}
|
|
29
18
|
exports.getPages = getPages;
|