astro-accelerator-utils 0.1.2 → 0.1.4

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 CHANGED
@@ -1,13 +1,13 @@
1
1
  import { DateFormatter } from "./lib/v1/dates.mjs";
2
- import { UrlFormatter } from "./lib/v1/urls.mjs";
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, UrlFormatter, Posts, Cache, PostQueries, PostFiltering, PostOrdering, PostPaging, FooterMenu, Markdown, Navigation, Taxonomy };
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 { UrlFormatter } from './lib/v1/urls.mjs';
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
- UrlFormatter,
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
  };
@@ -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.mjs CHANGED
@@ -4,6 +4,7 @@ export class Posts {
4
4
  * @param {() => MarkdownInstance[]} fetchAll
5
5
  */
6
6
  constructor(fetchAll) {
7
+ /* istanbul ignore next */
7
8
  this.fetchAll = fetchAll ?? function() { return import.meta.glob("/src/pages/**/*.md", { eager: true }); }
8
9
  this.allPosts = [];
9
10
  }
package/lib/v1/urls.mjs CHANGED
@@ -13,7 +13,14 @@ export class UrlFormatter {
13
13
  * @returns {URL}
14
14
  */
15
15
  addSlashToUrl(url) {
16
- url.pathname += url.pathname.endsWith('/') ? '' : '/';
16
+ if (!url) {
17
+ return new URL(this.siteUrl);
18
+ }
19
+
20
+ url.pathname += url.pathname.endsWith('/')
21
+ ? ''
22
+ : '/';
23
+
17
24
  return url;
18
25
  }
19
26
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "astro-accelerator-utils",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "Astro utilities for Astro Accelerator.",
5
5
  "main": "index.mjs",
6
6
  "type": "module",
@@ -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
- }