astro-accelerator-utils 0.0.32 → 0.0.33
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 +2 -1
- package/index.mjs +2 -0
- package/lib/markdown.d.mts +18 -0
- package/lib/markdown.mjs +45 -0
- package/lib/postQueries.d.mts +2 -2
- package/lib/postQueries.mjs +1 -1
- package/package.json +6 -2
package/index.d.mts
CHANGED
|
@@ -4,5 +4,6 @@ import * as PostOrdering from "./lib/postOrdering.mjs";
|
|
|
4
4
|
import * as PostPaging from "./lib/postPaging.mjs";
|
|
5
5
|
import * as Cache from "./lib/cache.mjs";
|
|
6
6
|
import * as Dates from "./lib/dates.mjs";
|
|
7
|
+
import * as Markdown from "./lib/markdown.mjs";
|
|
7
8
|
import * as Urls from "./lib/urls.mjs";
|
|
8
|
-
export { PostQueries, PostFiltering, PostOrdering, PostPaging, Cache, Dates, Urls };
|
|
9
|
+
export { PostQueries, PostFiltering, PostOrdering, PostPaging, Cache, Dates, Markdown, Urls };
|
package/index.mjs
CHANGED
|
@@ -4,6 +4,7 @@ import * as PostOrdering from './lib/postOrdering.mjs';
|
|
|
4
4
|
import * as PostPaging from './lib/postPaging.mjs';
|
|
5
5
|
import * as Cache from './lib/cache.mjs';
|
|
6
6
|
import * as Dates from './lib/dates.mjs';
|
|
7
|
+
import * as Markdown from './lib/markdown.mjs';
|
|
7
8
|
import * as Urls from './lib/urls.mjs';
|
|
8
9
|
|
|
9
10
|
export {
|
|
@@ -13,5 +14,6 @@ export {
|
|
|
13
14
|
PostPaging,
|
|
14
15
|
Cache,
|
|
15
16
|
Dates,
|
|
17
|
+
Markdown,
|
|
16
18
|
Urls
|
|
17
19
|
};
|
|
@@ -0,0 +1,18 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
}
|
package/lib/postQueries.d.mts
CHANGED
|
@@ -27,9 +27,9 @@ export function getAuthorInfo(slug: string): Promise<AuthorInfo>;
|
|
|
27
27
|
* Returns a list of breadcrumbs
|
|
28
28
|
* @param {URL} currentUrl
|
|
29
29
|
* @param {Site} site
|
|
30
|
-
* @returns {NavPage[]}
|
|
30
|
+
* @returns {Promise<NavPage[]>}
|
|
31
31
|
*/
|
|
32
|
-
export function getBreadcrumbs(currentUrl: URL, site: Site): NavPage[]
|
|
32
|
+
export function getBreadcrumbs(currentUrl: URL, site: Site): Promise<NavPage[]>;
|
|
33
33
|
/**
|
|
34
34
|
* Converts a MarkdownInstance into a NavPage
|
|
35
35
|
* @param {MarkdownInstance} page
|
package/lib/postQueries.mjs
CHANGED
|
@@ -144,7 +144,7 @@ export async function getAuthorInfo (slug) {
|
|
|
144
144
|
* Returns a list of breadcrumbs
|
|
145
145
|
* @param {URL} currentUrl
|
|
146
146
|
* @param {Site} site
|
|
147
|
-
* @returns {NavPage[]}
|
|
147
|
+
* @returns {Promise<NavPage[]>}
|
|
148
148
|
*/
|
|
149
149
|
export async function getBreadcrumbs (currentUrl, site) {
|
|
150
150
|
const allPages = await getPages();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astro-accelerator-utils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.33",
|
|
4
4
|
"description": "Astro utilities for Astro Accelerator.",
|
|
5
5
|
"main": "index.mjs",
|
|
6
6
|
"files": [
|
|
@@ -30,6 +30,10 @@
|
|
|
30
30
|
"homepage": "https://astro.stevefenton.co.uk/",
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@types/node": "^18.11.9",
|
|
33
|
-
"typescript": "^4.9.3"
|
|
33
|
+
"typescript": "^4.9.3",
|
|
34
|
+
"unified": "^10.1.2",
|
|
35
|
+
"remark-parse": "^10.0.1",
|
|
36
|
+
"remark-rehype": "^10.1.0",
|
|
37
|
+
"rehype-stringify": "^9.0.3"
|
|
34
38
|
}
|
|
35
39
|
}
|