astro-accelerator-utils 0.0.8 → 0.0.10

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.js CHANGED
@@ -1,6 +1,27 @@
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';
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addSlashToUrl = exports.addSlashToAddress = exports.getPages = 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; } });
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 postQueries_1 = require("./lib/postQueries");
24
+ Object.defineProperty(exports, "getPages", { enumerable: true, get: function () { return postQueries_1.getPages; } });
25
+ var urls_1 = require("./lib/urls");
26
+ Object.defineProperty(exports, "addSlashToAddress", { enumerable: true, get: function () { return urls_1.addSlashToAddress; } });
27
+ Object.defineProperty(exports, "addSlashToUrl", { enumerable: true, get: function () { return urls_1.addSlashToUrl; } });
package/dist/lib/Cache.js CHANGED
@@ -1,25 +1,33 @@
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 });
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.setItem = exports.getItem = exports.getItemPath = exports.getCachePath = exports.maxAge = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ const process_1 = __importDefault(require("process"));
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 });
8
14
  return cachePath;
9
15
  }
10
- export async function getItemPath(key) {
16
+ exports.getCachePath = getCachePath;
17
+ async function getItemPath(key) {
11
18
  const cachePath = await getCachePath();
12
- return path.join(cachePath, key + '.cache');
19
+ return path_1.default.join(cachePath, key + '.cache');
13
20
  }
14
- export async function getItem(key) {
21
+ exports.getItemPath = getItemPath;
22
+ async function getItem(key) {
15
23
  const itemPath = await getItemPath(key);
16
24
  try {
17
- const { mtime } = await fs.promises.stat(itemPath);
25
+ const { mtime } = await fs_1.default.promises.stat(itemPath);
18
26
  var date_time = new Date();
19
27
  let timeDifference = Math.abs((date_time.getTime() - mtime.getTime()) / 1000);
20
- if (timeDifference < maxAge) {
28
+ if (timeDifference < exports.maxAge) {
21
29
  console.log('Cache hit', key);
22
- const content = fs.readFileSync(itemPath).toString();
30
+ const content = fs_1.default.readFileSync(itemPath).toString();
23
31
  return JSON.parse(content);
24
32
  }
25
33
  }
@@ -27,7 +35,9 @@ export async function getItem(key) {
27
35
  console.warn('Cache miss', key);
28
36
  return null;
29
37
  }
30
- export async function setItem(key, value) {
38
+ exports.getItem = getItem;
39
+ async function setItem(key, value) {
31
40
  const itemPath = await getItemPath(key);
32
- await fs.promises.writeFile(itemPath, JSON.stringify(value));
41
+ await fs_1.default.promises.writeFile(itemPath, JSON.stringify(value));
33
42
  }
43
+ exports.setItem = setItem;
package/dist/lib/dates.js CHANGED
@@ -1,4 +1,7 @@
1
- export function formatDate(frontmatter, lang, site) {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.formatModifiedDate = exports.formatDate = void 0;
4
+ function formatDate(frontmatter, lang, site) {
2
5
  var _a;
3
6
  const date = (_a = frontmatter.pubDate) !== null && _a !== void 0 ? _a : '';
4
7
  if (date) {
@@ -6,7 +9,8 @@ export function formatDate(frontmatter, lang, site) {
6
9
  }
7
10
  return '';
8
11
  }
9
- export function formatModifiedDate(frontmatter, lang, site) {
12
+ exports.formatDate = formatDate;
13
+ function formatModifiedDate(frontmatter, lang, site) {
10
14
  var _a;
11
15
  const date = (_a = frontmatter.modDate) !== null && _a !== void 0 ? _a : '';
12
16
  if (date) {
@@ -14,3 +18,4 @@ export function formatModifiedDate(frontmatter, lang, site) {
14
18
  }
15
19
  return '';
16
20
  }
21
+ exports.formatModifiedDate = formatModifiedDate;
@@ -1,41 +1,50 @@
1
- export function showInSitemap(p) {
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) {
2
5
  if (typeof p.frontmatter.navSitemap !== 'undefined'
3
6
  && p.frontmatter.navSitemap == false) {
4
7
  return false;
5
8
  }
6
9
  return isListable(p);
7
10
  }
8
- export function showInSearch(p) {
11
+ exports.showInSitemap = showInSitemap;
12
+ function showInSearch(p) {
9
13
  if (typeof p.frontmatter.navSearch !== 'undefined'
10
14
  && p.frontmatter.navSearch == false) {
11
15
  return false;
12
16
  }
13
17
  return isListable(p);
14
18
  }
15
- export function showInMenu(p) {
19
+ exports.showInSearch = showInSearch;
20
+ function showInMenu(p) {
16
21
  if (typeof p.frontmatter.navMenu !== 'undefined'
17
22
  && p.frontmatter.navMenu == false) {
18
23
  return false;
19
24
  }
20
25
  return true;
21
26
  }
22
- export function isAuthor(p) {
27
+ exports.showInMenu = showInMenu;
28
+ function isAuthor(p) {
23
29
  var _a, _b;
24
30
  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) {
25
31
  return true;
26
32
  }
27
33
  return false;
28
34
  }
29
- export function isSearch(p) {
35
+ exports.isAuthor = isAuthor;
36
+ function isSearch(p) {
30
37
  var _a, _b;
31
38
  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) {
32
39
  return true;
33
40
  }
34
41
  return false;
35
42
  }
36
- export function isListable(p) {
43
+ exports.isSearch = isSearch;
44
+ function isListable(p) {
37
45
  return p.url != null
38
46
  && p.url != ''
39
47
  && p.frontmatter.layout.includes('/Redirect.astro') !== true
40
48
  && Date.parse(p.frontmatter.pubDate) < Date.now();
41
49
  }
50
+ exports.isListable = isListable;
@@ -1,11 +1,17 @@
1
- export function sortByPubDate(a, b) {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sortByModDate = exports.sortByPubDateDesc = exports.sortByPubDate = void 0;
4
+ function sortByPubDate(a, b) {
2
5
  return b.frontmatter.pubDate.localeCompare(a.frontmatter.pubDate);
3
6
  }
4
- export function sortByPubDateDesc(a, b) {
7
+ exports.sortByPubDate = sortByPubDate;
8
+ function sortByPubDateDesc(a, b) {
5
9
  return b.frontmatter.pubDate.localeCompare(a.frontmatter.pubDate);
6
10
  }
7
- export function sortByModDate(a, b) {
11
+ exports.sortByPubDateDesc = sortByPubDateDesc;
12
+ function sortByModDate(a, b) {
8
13
  const dateA = a.frontmatter.modDate || a.frontmatter.pubDate || '1970-01-01';
9
14
  const dateB = b.frontmatter.modDate || b.frontmatter.pubDate || '1970-01-01';
10
15
  return dateA.localeCompare(dateB);
11
16
  }
17
+ exports.sortByModDate = sortByModDate;
@@ -1,14 +1,18 @@
1
- import { getItem, setItem } from "./Cache";
2
- export async function getPages(fetchPages, filter) {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getPages = void 0;
4
+ const Cache_1 = require("./Cache");
5
+ async function getPages(fetchPages, filter) {
3
6
  const key = 'PageQueries__getPages';
4
- let allPages = await getItem(key);
7
+ let allPages = await (0, Cache_1.getItem)(key);
5
8
  if (allPages == null) {
6
9
  const pageImportResult = fetchPages();
7
10
  allPages = Object.values(pageImportResult);
8
- await setItem(key, allPages);
11
+ await (0, Cache_1.setItem)(key, allPages);
9
12
  }
10
13
  if (filter == null) {
11
14
  return allPages;
12
15
  }
13
16
  return allPages.filter(filter);
14
17
  }
18
+ exports.getPages = getPages;
package/dist/lib/urls.js CHANGED
@@ -1,8 +1,12 @@
1
- export function addSlashToUrl(url) {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.addSlashToAddress = exports.addSlashToUrl = void 0;
4
+ function addSlashToUrl(url) {
2
5
  url.pathname += url.pathname.endsWith('/') ? '' : '/';
3
6
  return url;
4
7
  }
5
- export function addSlashToAddress(address, site) {
8
+ exports.addSlashToUrl = addSlashToUrl;
9
+ function addSlashToAddress(address, site) {
6
10
  if (!address) {
7
11
  address = '/';
8
12
  }
@@ -12,3 +16,4 @@ export function addSlashToAddress(address, site) {
12
16
  const url = addSlashToUrl(new URL(address, site.url));
13
17
  return url.pathname + url.search;
14
18
  }
19
+ exports.addSlashToAddress = addSlashToAddress;
@@ -1 +1,2 @@
1
- export {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +1,2 @@
1
- export {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +1,2 @@
1
- export {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1 +1,2 @@
1
- export {};
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro-accelerator-utils",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "description": "Astro utilities for Astro Accelerator.",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {