astro-accelerator-utils 0.0.4 → 0.0.6
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 +5 -1
- package/dist/index.js +17 -1
- package/dist/lib/Cache.d.ts +5 -0
- package/dist/lib/Cache.js +60 -0
- package/dist/lib/dates.d.ts +2 -4
- package/dist/lib/postFiltering.d.ts +7 -0
- package/dist/lib/postFiltering.js +52 -0
- package/dist/lib/postOrdering.d.ts +4 -0
- package/dist/lib/postOrdering.js +17 -0
- package/dist/lib/postQueries.d.ts +1 -0
- package/dist/lib/postQueries.js +21 -0
- package/dist/lib/urls.d.ts +1 -2
- package/dist/types/Frontmatter.d.ts +1 -0
- package/dist/types/Frontmatter.js +2 -0
- package/dist/types/Markdown.d.ts +4 -0
- package/dist/types/Markdown.js +2 -0
- package/dist/types/Site.d.ts +34 -0
- package/dist/types/Site.js +2 -0
- package/package.json +3 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
export type { Site } from './Site';
|
|
1
|
+
export type { Site } from './types/Site';
|
|
2
|
+
export type { Frontmatter } from './types/Frontmatter';
|
|
3
|
+
export { getCachePath, getItem, getItemPath, setItem } from './lib/Cache';
|
|
2
4
|
export { formatDate, formatModifiedDate } from './lib/dates';
|
|
5
|
+
export { isAuthor, isListable, isSearch, showInMenu, showInSearch, showInSitemap } from './lib/postFiltering';
|
|
6
|
+
export { sortByModDate, sortByPubDate, sortByPubDateDesc } from './lib/postOrdering';
|
|
3
7
|
export { addSlashToAddress, addSlashToUrl } from './lib/urls';
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,25 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.addSlashToUrl = exports.addSlashToAddress = exports.formatModifiedDate = exports.formatDate = void 0;
|
|
3
|
+
exports.addSlashToUrl = exports.addSlashToAddress = exports.sortByPubDateDesc = exports.sortByPubDate = exports.sortByModDate = exports.showInSitemap = exports.showInSearch = exports.showInMenu = exports.isSearch = exports.isListable = exports.isAuthor = exports.formatModifiedDate = exports.formatDate = exports.setItem = exports.getItemPath = exports.getItem = exports.getCachePath = void 0;
|
|
4
|
+
var Cache_1 = require("./lib/Cache");
|
|
5
|
+
Object.defineProperty(exports, "getCachePath", { enumerable: true, get: function () { return Cache_1.getCachePath; } });
|
|
6
|
+
Object.defineProperty(exports, "getItem", { enumerable: true, get: function () { return Cache_1.getItem; } });
|
|
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; } });
|
|
4
9
|
var dates_1 = require("./lib/dates");
|
|
5
10
|
Object.defineProperty(exports, "formatDate", { enumerable: true, get: function () { return dates_1.formatDate; } });
|
|
6
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; } });
|
|
7
23
|
var urls_1 = require("./lib/urls");
|
|
8
24
|
Object.defineProperty(exports, "addSlashToAddress", { enumerable: true, get: function () { return urls_1.addSlashToAddress; } });
|
|
9
25
|
Object.defineProperty(exports, "addSlashToUrl", { enumerable: true, get: function () { return urls_1.addSlashToUrl; } });
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const maxAge = 200;
|
|
2
|
+
export declare function getCachePath(): Promise<string>;
|
|
3
|
+
export declare function getItemPath(key: string): Promise<string>;
|
|
4
|
+
export declare function getItem(key: string): Promise<any>;
|
|
5
|
+
export declare function setItem(key: string, value: object): Promise<void>;
|
|
@@ -0,0 +1,60 @@
|
|
|
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
|
+
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
|
+
});
|
|
26
|
+
}
|
|
27
|
+
exports.getCachePath = getCachePath;
|
|
28
|
+
function getItemPath(key) {
|
|
29
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
const cachePath = yield getCachePath();
|
|
31
|
+
return path_1.default.join(cachePath, key + '.cache');
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
exports.getItemPath = getItemPath;
|
|
35
|
+
function getItem(key) {
|
|
36
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
const itemPath = yield getItemPath(key);
|
|
38
|
+
try {
|
|
39
|
+
const { mtime } = yield fs_1.default.promises.stat(itemPath);
|
|
40
|
+
var date_time = new Date();
|
|
41
|
+
let timeDifference = Math.abs((date_time.getTime() - mtime.getTime()) / 1000);
|
|
42
|
+
if (timeDifference < exports.maxAge) {
|
|
43
|
+
console.log('Cache hit', key);
|
|
44
|
+
const content = fs_1.default.readFileSync(itemPath).toString();
|
|
45
|
+
return JSON.parse(content);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
catch (_a) { }
|
|
49
|
+
console.warn('Cache miss', key);
|
|
50
|
+
return null;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
exports.getItem = getItem;
|
|
54
|
+
function setItem(key, value) {
|
|
55
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
const itemPath = yield getItemPath(key);
|
|
57
|
+
yield fs_1.default.promises.writeFile(itemPath, JSON.stringify(value));
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
exports.setItem = setItem;
|
package/dist/lib/dates.d.ts
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import type { Site } from '../Site';
|
|
2
|
-
import type { Frontmatter } from '../Frontmatter';
|
|
3
|
-
export type { Site } from '../Site';
|
|
4
|
-
export type { Frontmatter as FrontMatter } from '../Frontmatter';
|
|
1
|
+
import type { Site } from '../types/Site';
|
|
2
|
+
import type { Frontmatter } from '../types/Frontmatter';
|
|
5
3
|
export declare function formatDate(frontmatter: Frontmatter, lang: string, site: Site): string;
|
|
6
4
|
export declare function formatModifiedDate(frontmatter: Frontmatter, lang: string, site: Site): string;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Markdown } from '../types/Markdown';
|
|
2
|
+
export declare function showInSitemap(p: Markdown<Record<string, any>>): boolean;
|
|
3
|
+
export declare function showInSearch(p: Markdown<Record<string, any>>): boolean;
|
|
4
|
+
export declare function showInMenu(p: Markdown<Record<string, any>>): boolean;
|
|
5
|
+
export declare function isAuthor(p: Markdown<Record<string, any>>): boolean;
|
|
6
|
+
export declare function isSearch(p: Markdown<Record<string, any>>): boolean;
|
|
7
|
+
export declare function isListable(p: Markdown<Record<string, any>>): boolean;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
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
|
|
6
|
+
if (typeof p.frontmatter.navSitemap !== 'undefined'
|
|
7
|
+
&& p.frontmatter.navSitemap == false) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
return isListable(p);
|
|
11
|
+
}
|
|
12
|
+
exports.showInSitemap = showInSitemap;
|
|
13
|
+
function showInSearch(p) {
|
|
14
|
+
// User setting to remove from search
|
|
15
|
+
if (typeof p.frontmatter.navSearch !== 'undefined'
|
|
16
|
+
&& p.frontmatter.navSearch == false) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
return isListable(p);
|
|
20
|
+
}
|
|
21
|
+
exports.showInSearch = showInSearch;
|
|
22
|
+
function showInMenu(p) {
|
|
23
|
+
if (typeof p.frontmatter.navMenu !== 'undefined'
|
|
24
|
+
&& p.frontmatter.navMenu == false) {
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
exports.showInMenu = showInMenu;
|
|
30
|
+
function isAuthor(p) {
|
|
31
|
+
var _a, _b;
|
|
32
|
+
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
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
exports.isAuthor = isAuthor;
|
|
38
|
+
function isSearch(p) {
|
|
39
|
+
var _a, _b;
|
|
40
|
+
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
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
return false;
|
|
44
|
+
}
|
|
45
|
+
exports.isSearch = isSearch;
|
|
46
|
+
function isListable(p) {
|
|
47
|
+
return p.url != null
|
|
48
|
+
&& p.url != ''
|
|
49
|
+
&& p.frontmatter.layout.includes('/Redirect.astro') !== true
|
|
50
|
+
&& Date.parse(p.frontmatter.pubDate) < Date.now();
|
|
51
|
+
}
|
|
52
|
+
exports.isListable = isListable;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { Markdown } from "../types/Markdown";
|
|
2
|
+
export declare function sortByPubDate(a: Markdown<Record<string, any>>, b: Markdown<Record<string, any>>): any;
|
|
3
|
+
export declare function sortByPubDateDesc(a: Markdown<Record<string, any>>, b: Markdown<Record<string, any>>): any;
|
|
4
|
+
export declare function sortByModDate(a: Markdown<Record<string, any>>, b: Markdown<Record<string, any>>): any;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sortByModDate = exports.sortByPubDateDesc = exports.sortByPubDate = void 0;
|
|
4
|
+
function sortByPubDate(a, b) {
|
|
5
|
+
return b.frontmatter.pubDate.localeCompare(a.frontmatter.pubDate);
|
|
6
|
+
}
|
|
7
|
+
exports.sortByPubDate = sortByPubDate;
|
|
8
|
+
function sortByPubDateDesc(a, b) {
|
|
9
|
+
return b.frontmatter.pubDate.localeCompare(a.frontmatter.pubDate);
|
|
10
|
+
}
|
|
11
|
+
exports.sortByPubDateDesc = sortByPubDateDesc;
|
|
12
|
+
function sortByModDate(a, b) {
|
|
13
|
+
const dateA = a.frontmatter.modDate || a.frontmatter.pubDate || '1970-01-01';
|
|
14
|
+
const dateB = b.frontmatter.modDate || b.frontmatter.pubDate || '1970-01-01';
|
|
15
|
+
return dateA.localeCompare(dateB);
|
|
16
|
+
}
|
|
17
|
+
exports.sortByModDate = sortByModDate;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function globTest(): any;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// export type PagePredicate = (value: MarkdownInstance<Record<string, any>>, index: number, array: MarkdownInstance<Record<string, any>>[]) => boolean;
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.globTest = void 0;
|
|
5
|
+
// export async function getPages (filter?: PagePredicate | null): Promise<MarkdownInstance<Record<string,any>>[]> {
|
|
6
|
+
// const key = 'PageQueries__getPages';
|
|
7
|
+
// let allPages: MarkdownInstance<Record<string,any>>[] = await getItem(key);
|
|
8
|
+
// if (allPages == null) {
|
|
9
|
+
// const pageImportResult = import.meta.glob("../../../pages/**/*.md", { eager: true });
|
|
10
|
+
// allPages = Object.values(pageImportResult) as MarkdownInstance<Record<string,any>>[];
|
|
11
|
+
// await setItem(key, allPages);
|
|
12
|
+
// }
|
|
13
|
+
// if (filter == null) {
|
|
14
|
+
// return allPages;
|
|
15
|
+
// }
|
|
16
|
+
// return allPages.filter(filter);
|
|
17
|
+
// }
|
|
18
|
+
function globTest() {
|
|
19
|
+
return import.meta.glob("../../../../src/pages/**/*.md", { eager: true });
|
|
20
|
+
}
|
|
21
|
+
exports.globTest = globTest;
|
package/dist/lib/urls.d.ts
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type Frontmatter = Record<string, any>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export type Site = {
|
|
2
|
+
url: string;
|
|
3
|
+
dateOptions: Intl.DateTimeFormatOptions;
|
|
4
|
+
subfolder: string;
|
|
5
|
+
feedUrl: string;
|
|
6
|
+
title: string;
|
|
7
|
+
description: string;
|
|
8
|
+
defaultLanguage: string;
|
|
9
|
+
themeColor: string;
|
|
10
|
+
owner: string;
|
|
11
|
+
default: {
|
|
12
|
+
lang: string;
|
|
13
|
+
locale: string;
|
|
14
|
+
dir: string;
|
|
15
|
+
};
|
|
16
|
+
search: {
|
|
17
|
+
fallbackUrl: 'https://www.google.com/search' | string;
|
|
18
|
+
fallbackSite: 'q' | string;
|
|
19
|
+
fallbackQuery: 'q' | string;
|
|
20
|
+
};
|
|
21
|
+
pageSize: number;
|
|
22
|
+
pageLinks: number;
|
|
23
|
+
rssLimit: number;
|
|
24
|
+
featureFlags: {
|
|
25
|
+
codeBlocks: 'copy'[];
|
|
26
|
+
figures: 'enlarge'[];
|
|
27
|
+
youTubeLinks: 'embed'[];
|
|
28
|
+
};
|
|
29
|
+
images: {
|
|
30
|
+
contentSize: string;
|
|
31
|
+
listerSize: string;
|
|
32
|
+
authorSize: string;
|
|
33
|
+
};
|
|
34
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro-accelerator-utils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.6",
|
|
4
4
|
"description": "Astro utilities for Astro Accelerator.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -25,6 +25,7 @@
|
|
|
25
25
|
},
|
|
26
26
|
"homepage": "https://astro.stevefenton.co.uk/",
|
|
27
27
|
"devDependencies": {
|
|
28
|
-
"typescript": "^4.9.3"
|
|
28
|
+
"typescript": "^4.9.3",
|
|
29
|
+
"@types/node": "^18.11.9"
|
|
29
30
|
}
|
|
30
31
|
}
|