@jam-comments/astro 2.5.1 → 2.6.1
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.ts +3 -0
- package/package.json +9 -9
- package/src/component.astro +23 -2
- package/src/utils.test.ts +42 -16
- package/src/utils.ts +9 -1
package/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { CustomCopy } from "@jam-comments/server-utilities";
|
|
2
|
+
|
|
1
3
|
declare global {
|
|
2
4
|
interface Window {
|
|
3
5
|
JamComments: {
|
|
@@ -14,6 +16,7 @@ export interface JamCommentsProps {
|
|
|
14
16
|
baseUrl?: string;
|
|
15
17
|
environment?: string;
|
|
16
18
|
tz?: string;
|
|
19
|
+
copy?: CustomCopy;
|
|
17
20
|
}
|
|
18
21
|
|
|
19
22
|
export default function JamComments(args: JamCommentsProps): JSX.Element;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jam-comments/astro",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.6.1",
|
|
4
4
|
"author": "Alex MacArthur <alex@macarthur.me> (https://macarthur.me)",
|
|
5
5
|
"license": "GPL-2.0",
|
|
6
6
|
"description": "Easily add performant, SEO-friendly comments to your Astro blog with JamComments.",
|
|
@@ -38,17 +38,17 @@
|
|
|
38
38
|
"access": "public"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@astrojs/check": "^0.
|
|
42
|
-
"@jam-comments/server-utilities": "^
|
|
43
|
-
"astro": "^4.
|
|
41
|
+
"@astrojs/check": "^0.8.2",
|
|
42
|
+
"@jam-comments/server-utilities": "^5.2.0",
|
|
43
|
+
"astro": "^4.11.6",
|
|
44
44
|
"node-fetch": "^3.3.2",
|
|
45
|
-
"typescript": "^5.
|
|
45
|
+
"typescript": "^5.5.3"
|
|
46
46
|
},
|
|
47
47
|
"gitHead": "2b1cefb90c89a2f70099213881b09216f20e3dc2",
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@types/node": "^20.
|
|
50
|
-
"prettier": "^3.
|
|
51
|
-
"prettier-plugin-astro": "^0.
|
|
52
|
-
"vitest": "^
|
|
49
|
+
"@types/node": "^20.14.11",
|
|
50
|
+
"prettier": "^3.3.3",
|
|
51
|
+
"prettier-plugin-astro": "^0.14.1",
|
|
52
|
+
"vitest": "^2.0.3"
|
|
53
53
|
}
|
|
54
54
|
}
|
package/src/component.astro
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import pkg from "@jam-comments/server-utilities";
|
|
3
3
|
import nodeFetch from "node-fetch";
|
|
4
4
|
import type { JamCommentsProps } from "..";
|
|
5
|
-
import { getCurrentPath } from "./utils";
|
|
5
|
+
import { getCurrentPath, removeFalseyValues } from "./utils";
|
|
6
6
|
const { logError, markupFetcher } = pkg;
|
|
7
7
|
|
|
8
8
|
type Props = JamCommentsProps;
|
|
@@ -10,6 +10,7 @@ type Props = JamCommentsProps;
|
|
|
10
10
|
const fetchMarkup = markupFetcher("astro", nodeFetch as any);
|
|
11
11
|
|
|
12
12
|
async function fetchCommentData({
|
|
13
|
+
copy,
|
|
13
14
|
tz = undefined,
|
|
14
15
|
path = undefined,
|
|
15
16
|
schema = undefined,
|
|
@@ -27,6 +28,17 @@ async function fetchCommentData({
|
|
|
27
28
|
baseUrl,
|
|
28
29
|
environment,
|
|
29
30
|
tz,
|
|
31
|
+
copy: removeFalseyValues({
|
|
32
|
+
copy_confirmation_message: copy.confirmationMessage,
|
|
33
|
+
copy_submit_button: copy.submitButton,
|
|
34
|
+
copy_name_placeholder: copy.submitButton,
|
|
35
|
+
copy_email_placeholder: copy.submitButton,
|
|
36
|
+
copy_comment_placeholder: copy.submitButton,
|
|
37
|
+
copy_write_tab: copy.submitButton,
|
|
38
|
+
copy_preview_tab: copy.submitButton,
|
|
39
|
+
copy_auth_button: copy.submitButton,
|
|
40
|
+
copy_log_out_button: copy.submitButton,
|
|
41
|
+
}),
|
|
30
42
|
});
|
|
31
43
|
} catch (e) {
|
|
32
44
|
logError(e as string);
|
|
@@ -34,7 +46,15 @@ async function fetchCommentData({
|
|
|
34
46
|
}
|
|
35
47
|
}
|
|
36
48
|
|
|
37
|
-
const {
|
|
49
|
+
const {
|
|
50
|
+
path,
|
|
51
|
+
domain,
|
|
52
|
+
baseUrl,
|
|
53
|
+
environment,
|
|
54
|
+
tz,
|
|
55
|
+
schema,
|
|
56
|
+
copy = {},
|
|
57
|
+
} = Astro.props as Props;
|
|
38
58
|
|
|
39
59
|
const markup = await fetchCommentData({
|
|
40
60
|
path: path || getCurrentPath(Astro),
|
|
@@ -43,6 +63,7 @@ const markup = await fetchCommentData({
|
|
|
43
63
|
baseUrl,
|
|
44
64
|
environment,
|
|
45
65
|
tz,
|
|
66
|
+
copy,
|
|
46
67
|
});
|
|
47
68
|
---
|
|
48
69
|
|
package/src/utils.test.ts
CHANGED
|
@@ -1,22 +1,48 @@
|
|
|
1
|
-
import { expect, it } from "vitest";
|
|
2
|
-
import { getCurrentPath } from "./utils";
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { getCurrentPath, removeFalseyValues } from "./utils";
|
|
3
|
+
import { AstroGlobal } from "astro";
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
describe("getCurrentPath()", () => {
|
|
6
|
+
it("should return the current path", () => {
|
|
7
|
+
const astro = {
|
|
8
|
+
request: {
|
|
9
|
+
url: "https://example.com/test",
|
|
10
|
+
},
|
|
11
|
+
} as AstroGlobal;
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
expect(getCurrentPath(astro)).toBe("/test");
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it("should ignore query parameters", () => {
|
|
17
|
+
const astro = {
|
|
18
|
+
request: {
|
|
19
|
+
url: "https://example.com/test?query=param",
|
|
20
|
+
},
|
|
21
|
+
} as AstroGlobal;
|
|
22
|
+
|
|
23
|
+
expect(getCurrentPath(astro)).toBe("/test");
|
|
24
|
+
});
|
|
12
25
|
});
|
|
13
26
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
};
|
|
27
|
+
describe("removeFalseyValues()", () => {
|
|
28
|
+
it("should remove falsey values", () => {
|
|
29
|
+
expect(removeFalseyValues({ a: 1, b: 0, d: null, e: "" })).toEqual({
|
|
30
|
+
a: 1,
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("should remove undefined items", () => {
|
|
35
|
+
const customCopy = {
|
|
36
|
+
copy_confirmation_message: "Thank you for your comment!",
|
|
37
|
+
copy_submit_button: "Submit",
|
|
38
|
+
copy_name_placeholder: undefined,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const result = removeFalseyValues(customCopy);
|
|
20
42
|
|
|
21
|
-
|
|
43
|
+
expect(result).toEqual({
|
|
44
|
+
copy_confirmation_message: "Thank you for your comment!",
|
|
45
|
+
copy_submit_button: "Submit",
|
|
46
|
+
});
|
|
47
|
+
});
|
|
22
48
|
});
|
package/src/utils.ts
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
import { AstroGlobal } from "astro";
|
|
2
|
+
|
|
3
|
+
export function getCurrentPath(astro: AstroGlobal) {
|
|
2
4
|
return new URL(astro.request.url).pathname;
|
|
3
5
|
}
|
|
6
|
+
|
|
7
|
+
export function removeFalseyValues<T>(obj: T): Partial<T> {
|
|
8
|
+
const filteredItems = Object.entries(obj).filter(([, value]) => value);
|
|
9
|
+
|
|
10
|
+
return Object.fromEntries(filteredItems) as Partial<T>;
|
|
11
|
+
}
|