astro-accelerator-utils 0.1.3 → 0.1.5
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/index.d.mts +3 -3
- package/index.mjs +4 -4
- package/lib/navigation.mjs +4 -2
- package/lib/postQueries.d.mts +2 -2
- package/lib/postQueries.mjs +2 -2
- package/lib/v1/dates.d.mts +2 -3
- package/lib/v1/dates.mjs +1 -2
- package/lib/v1/markdown.d.mts +20 -0
- package/lib/v1/markdown.mjs +47 -0
- package/lib/v1/posts.d.mts +16 -4
- package/lib/v1/posts.mjs +14 -1
- package/package.json +1 -1
- package/lib/markdown.d.mts +0 -18
- package/lib/markdown.mjs +0 -45
package/index.d.mts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { DateFormatter } from "./lib/v1/dates.mjs";
|
|
2
|
-
import {
|
|
2
|
+
import { Markdown } from "./lib/v1/markdown.mjs";
|
|
3
3
|
import { Posts } from "./lib/v1/posts.mjs";
|
|
4
|
+
import { UrlFormatter } from "./lib/v1/urls.mjs";
|
|
4
5
|
import * as Cache from "./lib/cache.mjs";
|
|
5
6
|
import * as PostQueries from "./lib/postQueries.mjs";
|
|
6
7
|
import * as PostFiltering from "./lib/postFiltering.mjs";
|
|
7
8
|
import * as PostOrdering from "./lib/postOrdering.mjs";
|
|
8
9
|
import * as PostPaging from "./lib/postPaging.mjs";
|
|
9
10
|
import * as FooterMenu from "./lib/footerMenu.mjs";
|
|
10
|
-
import * as Markdown from "./lib/markdown.mjs";
|
|
11
11
|
import * as Navigation from "./lib/navigation.mjs";
|
|
12
12
|
import * as Taxonomy from "./lib/taxonomy.mjs";
|
|
13
|
-
export { DateFormatter,
|
|
13
|
+
export { DateFormatter, Markdown, Posts, UrlFormatter, Cache, PostQueries, PostFiltering, PostOrdering, PostPaging, FooterMenu, Navigation, Taxonomy };
|
package/index.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { DateFormatter } from './lib/v1/dates.mjs';
|
|
2
|
-
import {
|
|
2
|
+
import { Markdown } from './lib/v1/markdown.mjs';
|
|
3
3
|
import { Posts } from './lib/v1/posts.mjs';
|
|
4
|
+
import { UrlFormatter } from './lib/v1/urls.mjs';
|
|
4
5
|
|
|
5
6
|
import * as Cache from './lib/cache.mjs';
|
|
6
7
|
import * as PostQueries from './lib/postQueries.mjs';
|
|
@@ -8,21 +9,20 @@ import * as PostFiltering from './lib/postFiltering.mjs';
|
|
|
8
9
|
import * as PostOrdering from './lib/postOrdering.mjs';
|
|
9
10
|
import * as PostPaging from './lib/postPaging.mjs';
|
|
10
11
|
import * as FooterMenu from './lib/footerMenu.mjs';
|
|
11
|
-
import * as Markdown from './lib/markdown.mjs';
|
|
12
12
|
import * as Navigation from './lib/navigation.mjs';
|
|
13
13
|
import * as Taxonomy from './lib/taxonomy.mjs';
|
|
14
14
|
|
|
15
15
|
export {
|
|
16
16
|
DateFormatter,
|
|
17
|
-
|
|
17
|
+
Markdown,
|
|
18
18
|
Posts,
|
|
19
|
+
UrlFormatter,
|
|
19
20
|
Cache,
|
|
20
21
|
PostQueries,
|
|
21
22
|
PostFiltering,
|
|
22
23
|
PostOrdering,
|
|
23
24
|
PostPaging,
|
|
24
25
|
FooterMenu,
|
|
25
|
-
Markdown,
|
|
26
26
|
Navigation,
|
|
27
27
|
Taxonomy
|
|
28
28
|
};
|
package/lib/navigation.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Posts } from './v1/posts.mjs';
|
|
1
2
|
import * as PostQueries from './postQueries.mjs';
|
|
2
3
|
import * as PostFiltering from './postFiltering.mjs';
|
|
3
4
|
import * as Cache from './cache.mjs';
|
|
@@ -66,13 +67,14 @@ export function isNavPage (item) {
|
|
|
66
67
|
export async function getNavigation (currentUrl, site) {
|
|
67
68
|
|
|
68
69
|
const key = 'Navigation__getNavigation';
|
|
70
|
+
const posts = new Posts();
|
|
69
71
|
|
|
70
72
|
/** @type {NavPage[]} */
|
|
71
73
|
let pageHierarchy = await Cache.getItem(key);
|
|
72
74
|
|
|
73
75
|
if (pageHierarchy == null) {
|
|
74
|
-
const topLevelPages =
|
|
75
|
-
const allPages =
|
|
76
|
+
const topLevelPages = posts.root(site.subfolder).filter(PostFiltering.showInMenu);
|
|
77
|
+
const allPages = posts.all().filter(PostFiltering.showInMenu);
|
|
76
78
|
|
|
77
79
|
pageHierarchy = topLevelPages
|
|
78
80
|
.map(p => PostQueries.mapNavPage(p, site))
|
package/lib/postQueries.d.mts
CHANGED
|
@@ -5,14 +5,14 @@
|
|
|
5
5
|
export function injectFetchAll(fetcher: () => MarkdownInstance[]): void;
|
|
6
6
|
/**
|
|
7
7
|
* Replaced by Posts.all()
|
|
8
|
-
* Use Posts.all().filter(...) to filter results
|
|
8
|
+
* @deprecated Use Posts.all().filter(...) to filter results
|
|
9
9
|
* @param {PagePredicate} [filter]
|
|
10
10
|
* @returns {Promise<MarkdownInstance[]>}
|
|
11
11
|
*/
|
|
12
12
|
export function getPages(filter?: PagePredicate): Promise<MarkdownInstance[]>;
|
|
13
13
|
/**
|
|
14
14
|
* Replaced by Posts.root()
|
|
15
|
-
* Use Posts.root().filter(...) to filter results
|
|
15
|
+
* @deprecated Use Posts.root().filter(...) to filter results
|
|
16
16
|
* @param {Site} site
|
|
17
17
|
* @param {PagePredicate} [filter]
|
|
18
18
|
* @returns {Promise<MarkdownInstance[]>}
|
package/lib/postQueries.mjs
CHANGED
|
@@ -28,7 +28,7 @@ export function injectFetchAll (fetcher) {
|
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
30
|
* Replaced by Posts.all()
|
|
31
|
-
* Use Posts.all().filter(...) to filter results
|
|
31
|
+
* @deprecated Use Posts.all().filter(...) to filter results
|
|
32
32
|
* @param {PagePredicate} [filter]
|
|
33
33
|
* @returns {Promise<MarkdownInstance[]>}
|
|
34
34
|
*/
|
|
@@ -51,7 +51,7 @@ export async function getPages (filter) {
|
|
|
51
51
|
|
|
52
52
|
/**
|
|
53
53
|
* Replaced by Posts.root()
|
|
54
|
-
* Use Posts.root().filter(...) to filter results
|
|
54
|
+
* @deprecated Use Posts.root().filter(...) to filter results
|
|
55
55
|
* @param {Site} site
|
|
56
56
|
* @param {PagePredicate} [filter]
|
|
57
57
|
* @returns {Promise<MarkdownInstance[]>}
|
package/lib/v1/dates.d.mts
CHANGED
|
@@ -10,11 +10,10 @@ export class DateFormatter {
|
|
|
10
10
|
dateOptions: Intl.DateTimeFormatOptions;
|
|
11
11
|
/**
|
|
12
12
|
* Returns the formatted pubDate
|
|
13
|
-
* @param {
|
|
13
|
+
* @param {string | Date} date
|
|
14
14
|
* @param {string} lang
|
|
15
|
-
* @param {Site} site
|
|
16
15
|
* @returns {string}
|
|
17
16
|
*/
|
|
18
|
-
formatDate(date:
|
|
17
|
+
formatDate(date: string | Date, lang: string): string;
|
|
19
18
|
}
|
|
20
19
|
export type Site = any;
|
package/lib/v1/dates.mjs
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export class Markdown {
|
|
2
|
+
/**
|
|
3
|
+
* Converts markdown to HTML without wrapping in a <p>
|
|
4
|
+
* @param {string} markdown
|
|
5
|
+
* @returns {Promise<string>}
|
|
6
|
+
*/
|
|
7
|
+
getInlineHtmlFrom(markdown: string): Promise<string>;
|
|
8
|
+
/**
|
|
9
|
+
* Converts markdown to HTML
|
|
10
|
+
* @param {string} markdown
|
|
11
|
+
* @returns {Promise<string>}
|
|
12
|
+
*/
|
|
13
|
+
getHtmlFrom(markdown: string): Promise<string>;
|
|
14
|
+
/**
|
|
15
|
+
* Converts markdown to plain text
|
|
16
|
+
* @param {string} markdown
|
|
17
|
+
* @returns {Promise<string>}
|
|
18
|
+
*/
|
|
19
|
+
getTextFrom(markdown: string): Promise<string>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { unified } from 'unified';
|
|
2
|
+
import remarkParse from 'remark-parse';
|
|
3
|
+
import remarkRehype from 'remark-rehype'
|
|
4
|
+
import rehypeStringify from 'rehype-stringify';
|
|
5
|
+
|
|
6
|
+
export class Markdown {
|
|
7
|
+
/**
|
|
8
|
+
* Converts markdown to HTML without wrapping in a <p>
|
|
9
|
+
* @param {string} markdown
|
|
10
|
+
* @returns {Promise<string>}
|
|
11
|
+
*/
|
|
12
|
+
async getInlineHtmlFrom(markdown) {
|
|
13
|
+
let html = await this.getHtmlFrom(markdown);
|
|
14
|
+
|
|
15
|
+
// There may be a better way to unwrap this... maybe a visitor
|
|
16
|
+
if (html.substring(0, 3) == '<p>' && html.substring(html.length - 4) == '</p>') {
|
|
17
|
+
html = html.substring(3, html.length - 4);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return html;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Converts markdown to HTML
|
|
25
|
+
* @param {string} markdown
|
|
26
|
+
* @returns {Promise<string>}
|
|
27
|
+
*/
|
|
28
|
+
async getHtmlFrom(markdown) {
|
|
29
|
+
const vfile = await unified()
|
|
30
|
+
.use(remarkParse)
|
|
31
|
+
.use(remarkRehype)
|
|
32
|
+
.use(rehypeStringify)
|
|
33
|
+
.process(markdown)
|
|
34
|
+
|
|
35
|
+
return String(vfile);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Converts markdown to plain text
|
|
40
|
+
* @param {string} markdown
|
|
41
|
+
* @returns {Promise<string>}
|
|
42
|
+
*/
|
|
43
|
+
async getTextFrom(markdown) {
|
|
44
|
+
const html = await this.getInlineHtmlFrom(markdown);
|
|
45
|
+
return html.replace(/<.*?>/g, '');
|
|
46
|
+
}
|
|
47
|
+
}
|
package/lib/v1/posts.d.mts
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef { import("../../types/Astro").MarkdownInstance } MarkdownInstance
|
|
3
|
+
*/
|
|
1
4
|
export class Posts {
|
|
2
5
|
/**
|
|
3
6
|
* Constructor
|
|
4
|
-
* @param {() => MarkdownInstance[]} fetchAll
|
|
7
|
+
* @param {() => MarkdownInstance[]} [fetchAll]
|
|
5
8
|
*/
|
|
6
|
-
constructor(fetchAll
|
|
9
|
+
constructor(fetchAll?: () => MarkdownInstance[]);
|
|
7
10
|
fetchAll: () => any;
|
|
8
11
|
allPosts: any[];
|
|
9
|
-
|
|
10
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Gets all markdown posts in the site
|
|
14
|
+
* @returns {MarkdownInstance[]}
|
|
15
|
+
*/
|
|
16
|
+
all(): MarkdownInstance[];
|
|
17
|
+
/**
|
|
18
|
+
* Gets top-level markdown posts in the site
|
|
19
|
+
* @returns {MarkdownInstance[]}
|
|
20
|
+
*/
|
|
21
|
+
root(subfolder: any): MarkdownInstance[];
|
|
11
22
|
}
|
|
23
|
+
export type MarkdownInstance = import("../../types/Astro").MarkdownInstance;
|
package/lib/v1/posts.mjs
CHANGED
|
@@ -1,13 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @typedef { import("../../types/Astro").MarkdownInstance } MarkdownInstance
|
|
3
|
+
*/
|
|
4
|
+
|
|
1
5
|
export class Posts {
|
|
2
6
|
/**
|
|
3
7
|
* Constructor
|
|
4
|
-
* @param {() => MarkdownInstance[]} fetchAll
|
|
8
|
+
* @param {() => MarkdownInstance[]} [fetchAll]
|
|
5
9
|
*/
|
|
6
10
|
constructor(fetchAll) {
|
|
11
|
+
/* istanbul ignore next */
|
|
7
12
|
this.fetchAll = fetchAll ?? function() { return import.meta.glob("/src/pages/**/*.md", { eager: true }); }
|
|
8
13
|
this.allPosts = [];
|
|
9
14
|
}
|
|
10
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Gets all markdown posts in the site
|
|
18
|
+
* @returns {MarkdownInstance[]}
|
|
19
|
+
*/
|
|
11
20
|
all () {
|
|
12
21
|
if (this.allPosts.length === 0) {
|
|
13
22
|
const pageImportResult = this.fetchAll();
|
|
@@ -17,6 +26,10 @@ export class Posts {
|
|
|
17
26
|
return this.allPosts;
|
|
18
27
|
}
|
|
19
28
|
|
|
29
|
+
/**
|
|
30
|
+
* Gets top-level markdown posts in the site
|
|
31
|
+
* @returns {MarkdownInstance[]}
|
|
32
|
+
*/
|
|
20
33
|
root (subfolder) {
|
|
21
34
|
const isRoot = subfolder.length == 0;
|
|
22
35
|
const expectedDepth = isRoot ? 1 : 2;
|
package/package.json
CHANGED
package/lib/markdown.d.mts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Converts markdown to HTML without wrapping in a <p>
|
|
3
|
-
* @param {string} markdown
|
|
4
|
-
* @returns {Promise<string>}
|
|
5
|
-
*/
|
|
6
|
-
export function getInlineHtmlFrom(markdown: string): Promise<string>;
|
|
7
|
-
/**
|
|
8
|
-
* Converts markdown to HTML
|
|
9
|
-
* @param {string} markdown
|
|
10
|
-
* @returns {Promise<string>}
|
|
11
|
-
*/
|
|
12
|
-
export function getHtmlFrom(markdown: string): Promise<string>;
|
|
13
|
-
/**
|
|
14
|
-
* Converts markdown to plain text
|
|
15
|
-
* @param {string} markdown
|
|
16
|
-
* @returns {Promise<string>}
|
|
17
|
-
*/
|
|
18
|
-
export function getTextFrom(markdown: string): Promise<string>;
|
package/lib/markdown.mjs
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { unified } from 'unified';
|
|
2
|
-
import remarkParse from 'remark-parse';
|
|
3
|
-
import remarkRehype from 'remark-rehype'
|
|
4
|
-
import rehypeStringify from 'rehype-stringify';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Converts markdown to HTML without wrapping in a <p>
|
|
8
|
-
* @param {string} markdown
|
|
9
|
-
* @returns {Promise<string>}
|
|
10
|
-
*/
|
|
11
|
-
export async function getInlineHtmlFrom(markdown) {
|
|
12
|
-
let html = await getHtmlFrom(markdown);
|
|
13
|
-
|
|
14
|
-
// There may be a better way to unwrap this... maybe a visitor
|
|
15
|
-
if (html.substring(0, 3) == '<p>' && html.substring(html.length - 4) == '</p>') {
|
|
16
|
-
html = html.substring(3, html.length - 4);
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
return html;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Converts markdown to HTML
|
|
24
|
-
* @param {string} markdown
|
|
25
|
-
* @returns {Promise<string>}
|
|
26
|
-
*/
|
|
27
|
-
export async function getHtmlFrom(markdown) {
|
|
28
|
-
const vfile = await unified()
|
|
29
|
-
.use(remarkParse)
|
|
30
|
-
.use(remarkRehype)
|
|
31
|
-
.use(rehypeStringify)
|
|
32
|
-
.process(markdown)
|
|
33
|
-
|
|
34
|
-
return String(vfile);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Converts markdown to plain text
|
|
39
|
-
* @param {string} markdown
|
|
40
|
-
* @returns {Promise<string>}
|
|
41
|
-
*/
|
|
42
|
-
export async function getTextFrom(markdown) {
|
|
43
|
-
const html = await getInlineHtmlFrom(markdown);
|
|
44
|
-
return html.replace(/<.*?>/g, '');
|
|
45
|
-
}
|