astro-accelerator-utils 0.0.6 → 0.0.8
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/index.d.ts +3 -1
- package/dist/index.js +6 -25
- package/dist/lib/Cache.js +28 -55
- package/dist/lib/dates.js +2 -7
- package/dist/lib/postFiltering.js +6 -17
- package/dist/lib/postOrdering.js +3 -9
- package/dist/lib/postQueries.d.ts +3 -1
- package/dist/lib/postQueries.js +13 -20
- package/dist/lib/urls.js +2 -7
- package/dist/types/Frontmatter.js +1 -2
- package/dist/types/Markdown.js +1 -2
- package/dist/types/PagePredicate.d.ts +2 -0
- package/dist/types/PagePredicate.js +1 -0
- package/dist/types/Site.js +1 -2
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
export type { Site } from './types/Site';
|
|
2
1
|
export type { Frontmatter } from './types/Frontmatter';
|
|
2
|
+
export type { PagePredicate } from './types/PagePredicate';
|
|
3
|
+
export type { Site } from './types/Site';
|
|
3
4
|
export { getCachePath, getItem, getItemPath, setItem } from './lib/Cache';
|
|
4
5
|
export { formatDate, formatModifiedDate } from './lib/dates';
|
|
5
6
|
export { isAuthor, isListable, isSearch, showInMenu, showInSearch, showInSitemap } from './lib/postFiltering';
|
|
6
7
|
export { sortByModDate, sortByPubDate, sortByPubDateDesc } from './lib/postOrdering';
|
|
8
|
+
export { getPages } from './lib/postQueries';
|
|
7
9
|
export { addSlashToAddress, addSlashToUrl } from './lib/urls';
|
package/dist/index.js
CHANGED
|
@@ -1,25 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
Object.defineProperty(exports, "getItemPath", { enumerable: true, get: function () { return Cache_1.getItemPath; } });
|
|
8
|
-
Object.defineProperty(exports, "setItem", { enumerable: true, get: function () { return Cache_1.setItem; } });
|
|
9
|
-
var dates_1 = require("./lib/dates");
|
|
10
|
-
Object.defineProperty(exports, "formatDate", { enumerable: true, get: function () { return dates_1.formatDate; } });
|
|
11
|
-
Object.defineProperty(exports, "formatModifiedDate", { enumerable: true, get: function () { return dates_1.formatModifiedDate; } });
|
|
12
|
-
var postFiltering_1 = require("./lib/postFiltering");
|
|
13
|
-
Object.defineProperty(exports, "isAuthor", { enumerable: true, get: function () { return postFiltering_1.isAuthor; } });
|
|
14
|
-
Object.defineProperty(exports, "isListable", { enumerable: true, get: function () { return postFiltering_1.isListable; } });
|
|
15
|
-
Object.defineProperty(exports, "isSearch", { enumerable: true, get: function () { return postFiltering_1.isSearch; } });
|
|
16
|
-
Object.defineProperty(exports, "showInMenu", { enumerable: true, get: function () { return postFiltering_1.showInMenu; } });
|
|
17
|
-
Object.defineProperty(exports, "showInSearch", { enumerable: true, get: function () { return postFiltering_1.showInSearch; } });
|
|
18
|
-
Object.defineProperty(exports, "showInSitemap", { enumerable: true, get: function () { return postFiltering_1.showInSitemap; } });
|
|
19
|
-
var postOrdering_1 = require("./lib/postOrdering");
|
|
20
|
-
Object.defineProperty(exports, "sortByModDate", { enumerable: true, get: function () { return postOrdering_1.sortByModDate; } });
|
|
21
|
-
Object.defineProperty(exports, "sortByPubDate", { enumerable: true, get: function () { return postOrdering_1.sortByPubDate; } });
|
|
22
|
-
Object.defineProperty(exports, "sortByPubDateDesc", { enumerable: true, get: function () { return postOrdering_1.sortByPubDateDesc; } });
|
|
23
|
-
var urls_1 = require("./lib/urls");
|
|
24
|
-
Object.defineProperty(exports, "addSlashToAddress", { enumerable: true, get: function () { return urls_1.addSlashToAddress; } });
|
|
25
|
-
Object.defineProperty(exports, "addSlashToUrl", { enumerable: true, get: function () { return urls_1.addSlashToUrl; } });
|
|
1
|
+
export { getCachePath, getItem, getItemPath, setItem } from './lib/Cache';
|
|
2
|
+
export { formatDate, formatModifiedDate } from './lib/dates';
|
|
3
|
+
export { isAuthor, isListable, isSearch, showInMenu, showInSearch, showInSitemap } from './lib/postFiltering';
|
|
4
|
+
export { sortByModDate, sortByPubDate, sortByPubDateDesc } from './lib/postOrdering';
|
|
5
|
+
export { getPages } from './lib/postQueries';
|
|
6
|
+
export { addSlashToAddress, addSlashToUrl } from './lib/urls';
|
package/dist/lib/Cache.js
CHANGED
|
@@ -1,60 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
-
};
|
|
14
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
-
exports.setItem = exports.getItem = exports.getItemPath = exports.getCachePath = exports.maxAge = void 0;
|
|
16
|
-
const fs_1 = __importDefault(require("fs"));
|
|
17
|
-
const path_1 = __importDefault(require("path"));
|
|
18
|
-
const process_1 = __importDefault(require("process"));
|
|
19
|
-
exports.maxAge = 200; //seconds
|
|
20
|
-
function getCachePath() {
|
|
21
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
22
|
-
const cachePath = path_1.default.join(process_1.default.cwd(), '.cache/');
|
|
23
|
-
yield fs_1.default.promises.mkdir(cachePath, { recursive: true });
|
|
24
|
-
return cachePath;
|
|
25
|
-
});
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import process from 'process';
|
|
4
|
+
export const maxAge = 200;
|
|
5
|
+
export async function getCachePath() {
|
|
6
|
+
const cachePath = path.join(process.cwd(), '.cache/');
|
|
7
|
+
await fs.promises.mkdir(cachePath, { recursive: true });
|
|
8
|
+
return cachePath;
|
|
26
9
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return
|
|
30
|
-
const cachePath = yield getCachePath();
|
|
31
|
-
return path_1.default.join(cachePath, key + '.cache');
|
|
32
|
-
});
|
|
10
|
+
export async function getItemPath(key) {
|
|
11
|
+
const cachePath = await getCachePath();
|
|
12
|
+
return path.join(cachePath, key + '.cache');
|
|
33
13
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const content = fs_1.default.readFileSync(itemPath).toString();
|
|
45
|
-
return JSON.parse(content);
|
|
46
|
-
}
|
|
14
|
+
export async function getItem(key) {
|
|
15
|
+
const itemPath = await getItemPath(key);
|
|
16
|
+
try {
|
|
17
|
+
const { mtime } = await fs.promises.stat(itemPath);
|
|
18
|
+
var date_time = new Date();
|
|
19
|
+
let timeDifference = Math.abs((date_time.getTime() - mtime.getTime()) / 1000);
|
|
20
|
+
if (timeDifference < maxAge) {
|
|
21
|
+
console.log('Cache hit', key);
|
|
22
|
+
const content = fs.readFileSync(itemPath).toString();
|
|
23
|
+
return JSON.parse(content);
|
|
47
24
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
25
|
+
}
|
|
26
|
+
catch { }
|
|
27
|
+
console.warn('Cache miss', key);
|
|
28
|
+
return null;
|
|
52
29
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const itemPath = yield getItemPath(key);
|
|
57
|
-
yield fs_1.default.promises.writeFile(itemPath, JSON.stringify(value));
|
|
58
|
-
});
|
|
30
|
+
export async function setItem(key, value) {
|
|
31
|
+
const itemPath = await getItemPath(key);
|
|
32
|
+
await fs.promises.writeFile(itemPath, JSON.stringify(value));
|
|
59
33
|
}
|
|
60
|
-
exports.setItem = setItem;
|
package/dist/lib/dates.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.formatModifiedDate = exports.formatDate = void 0;
|
|
4
|
-
function formatDate(frontmatter, lang, site) {
|
|
1
|
+
export function formatDate(frontmatter, lang, site) {
|
|
5
2
|
var _a;
|
|
6
3
|
const date = (_a = frontmatter.pubDate) !== null && _a !== void 0 ? _a : '';
|
|
7
4
|
if (date) {
|
|
@@ -9,8 +6,7 @@ function formatDate(frontmatter, lang, site) {
|
|
|
9
6
|
}
|
|
10
7
|
return '';
|
|
11
8
|
}
|
|
12
|
-
|
|
13
|
-
function formatModifiedDate(frontmatter, lang, site) {
|
|
9
|
+
export function formatModifiedDate(frontmatter, lang, site) {
|
|
14
10
|
var _a;
|
|
15
11
|
const date = (_a = frontmatter.modDate) !== null && _a !== void 0 ? _a : '';
|
|
16
12
|
if (date) {
|
|
@@ -18,4 +14,3 @@ function formatModifiedDate(frontmatter, lang, site) {
|
|
|
18
14
|
}
|
|
19
15
|
return '';
|
|
20
16
|
}
|
|
21
|
-
exports.formatModifiedDate = formatModifiedDate;
|
|
@@ -1,52 +1,41 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isListable = exports.isSearch = exports.isAuthor = exports.showInMenu = exports.showInSearch = exports.showInSitemap = void 0;
|
|
4
|
-
function showInSitemap(p) {
|
|
5
|
-
// User setting to remove from sitemap
|
|
1
|
+
export function showInSitemap(p) {
|
|
6
2
|
if (typeof p.frontmatter.navSitemap !== 'undefined'
|
|
7
3
|
&& p.frontmatter.navSitemap == false) {
|
|
8
4
|
return false;
|
|
9
5
|
}
|
|
10
6
|
return isListable(p);
|
|
11
7
|
}
|
|
12
|
-
|
|
13
|
-
function showInSearch(p) {
|
|
14
|
-
// User setting to remove from search
|
|
8
|
+
export function showInSearch(p) {
|
|
15
9
|
if (typeof p.frontmatter.navSearch !== 'undefined'
|
|
16
10
|
&& p.frontmatter.navSearch == false) {
|
|
17
11
|
return false;
|
|
18
12
|
}
|
|
19
13
|
return isListable(p);
|
|
20
14
|
}
|
|
21
|
-
|
|
22
|
-
function showInMenu(p) {
|
|
15
|
+
export function showInMenu(p) {
|
|
23
16
|
if (typeof p.frontmatter.navMenu !== 'undefined'
|
|
24
17
|
&& p.frontmatter.navMenu == false) {
|
|
25
18
|
return false;
|
|
26
19
|
}
|
|
27
20
|
return true;
|
|
28
21
|
}
|
|
29
|
-
|
|
30
|
-
function isAuthor(p) {
|
|
22
|
+
export function isAuthor(p) {
|
|
31
23
|
var _a, _b;
|
|
32
24
|
if (((_b = (_a = p === null || p === void 0 ? void 0 : p.frontmatter) === null || _a === void 0 ? void 0 : _a.layout) === null || _b === void 0 ? void 0 : _b.indexOf('/Author.astro')) > -1) {
|
|
33
25
|
return true;
|
|
34
26
|
}
|
|
35
27
|
return false;
|
|
36
28
|
}
|
|
37
|
-
|
|
38
|
-
function isSearch(p) {
|
|
29
|
+
export function isSearch(p) {
|
|
39
30
|
var _a, _b;
|
|
40
31
|
if (((_b = (_a = p === null || p === void 0 ? void 0 : p.frontmatter) === null || _a === void 0 ? void 0 : _a.layout) === null || _b === void 0 ? void 0 : _b.indexOf('/Search.astro')) > -1) {
|
|
41
32
|
return true;
|
|
42
33
|
}
|
|
43
34
|
return false;
|
|
44
35
|
}
|
|
45
|
-
|
|
46
|
-
function isListable(p) {
|
|
36
|
+
export function isListable(p) {
|
|
47
37
|
return p.url != null
|
|
48
38
|
&& p.url != ''
|
|
49
39
|
&& p.frontmatter.layout.includes('/Redirect.astro') !== true
|
|
50
40
|
&& Date.parse(p.frontmatter.pubDate) < Date.now();
|
|
51
41
|
}
|
|
52
|
-
exports.isListable = isListable;
|
package/dist/lib/postOrdering.js
CHANGED
|
@@ -1,17 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.sortByModDate = exports.sortByPubDateDesc = exports.sortByPubDate = void 0;
|
|
4
|
-
function sortByPubDate(a, b) {
|
|
1
|
+
export function sortByPubDate(a, b) {
|
|
5
2
|
return b.frontmatter.pubDate.localeCompare(a.frontmatter.pubDate);
|
|
6
3
|
}
|
|
7
|
-
|
|
8
|
-
function sortByPubDateDesc(a, b) {
|
|
4
|
+
export function sortByPubDateDesc(a, b) {
|
|
9
5
|
return b.frontmatter.pubDate.localeCompare(a.frontmatter.pubDate);
|
|
10
6
|
}
|
|
11
|
-
|
|
12
|
-
function sortByModDate(a, b) {
|
|
7
|
+
export function sortByModDate(a, b) {
|
|
13
8
|
const dateA = a.frontmatter.modDate || a.frontmatter.pubDate || '1970-01-01';
|
|
14
9
|
const dateB = b.frontmatter.modDate || b.frontmatter.pubDate || '1970-01-01';
|
|
15
10
|
return dateA.localeCompare(dateB);
|
|
16
11
|
}
|
|
17
|
-
exports.sortByModDate = sortByModDate;
|
|
@@ -1 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import { Markdown } from "../types/Markdown";
|
|
2
|
+
import { PagePredicate } from "../types/PagePredicate";
|
|
3
|
+
export declare function getPages(fetchPages: () => Record<string, any>, filter?: PagePredicate | null): Promise<Markdown<Record<string, any>>[]>;
|
package/dist/lib/postQueries.js
CHANGED
|
@@ -1,21 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
// return allPages;
|
|
15
|
-
// }
|
|
16
|
-
// return allPages.filter(filter);
|
|
17
|
-
// }
|
|
18
|
-
function globTest() {
|
|
19
|
-
return import.meta.glob("../../../../src/pages/**/*.md", { eager: true });
|
|
1
|
+
import { getItem, setItem } from "./Cache";
|
|
2
|
+
export async function getPages(fetchPages, filter) {
|
|
3
|
+
const key = 'PageQueries__getPages';
|
|
4
|
+
let allPages = await getItem(key);
|
|
5
|
+
if (allPages == null) {
|
|
6
|
+
const pageImportResult = fetchPages();
|
|
7
|
+
allPages = Object.values(pageImportResult);
|
|
8
|
+
await setItem(key, allPages);
|
|
9
|
+
}
|
|
10
|
+
if (filter == null) {
|
|
11
|
+
return allPages;
|
|
12
|
+
}
|
|
13
|
+
return allPages.filter(filter);
|
|
20
14
|
}
|
|
21
|
-
exports.globTest = globTest;
|
package/dist/lib/urls.js
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.addSlashToAddress = exports.addSlashToUrl = void 0;
|
|
4
|
-
function addSlashToUrl(url) {
|
|
1
|
+
export function addSlashToUrl(url) {
|
|
5
2
|
url.pathname += url.pathname.endsWith('/') ? '' : '/';
|
|
6
3
|
return url;
|
|
7
4
|
}
|
|
8
|
-
|
|
9
|
-
function addSlashToAddress(address, site) {
|
|
5
|
+
export function addSlashToAddress(address, site) {
|
|
10
6
|
if (!address) {
|
|
11
7
|
address = '/';
|
|
12
8
|
}
|
|
@@ -16,4 +12,3 @@ function addSlashToAddress(address, site) {
|
|
|
16
12
|
const url = addSlashToUrl(new URL(address, site.url));
|
|
17
13
|
return url.pathname + url.search;
|
|
18
14
|
}
|
|
19
|
-
exports.addSlashToAddress = addSlashToAddress;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
package/dist/types/Markdown.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/types/Site.js
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|