@jam-comments/astro 2.6.0 → 2.6.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jam-comments/astro",
3
- "version": "2.6.0",
3
+ "version": "2.6.2",
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.",
@@ -40,7 +40,7 @@
40
40
  "dependencies": {
41
41
  "@astrojs/check": "^0.8.2",
42
42
  "@jam-comments/server-utilities": "^5.2.0",
43
- "astro": "^4.11.6",
43
+ "astro": "^4.12.2",
44
44
  "node-fetch": "^3.3.2",
45
45
  "typescript": "^5.5.3"
46
46
  },
@@ -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;
@@ -28,17 +28,17 @@ async function fetchCommentData({
28
28
  baseUrl,
29
29
  environment,
30
30
  tz,
31
- copy: {
31
+ copy: removeFalseyValues({
32
32
  copy_confirmation_message: copy.confirmationMessage,
33
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
- },
34
+ copy_name_placeholder: copy.namePlaceholder,
35
+ copy_email_placeholder: copy.emailPlaceholder,
36
+ copy_comment_placeholder: copy.commentPlaceholder,
37
+ copy_write_tab: copy.writeTab,
38
+ copy_preview_tab: copy.previewTab,
39
+ copy_auth_button: copy.authButton,
40
+ copy_log_out_button: copy.logOutButton,
41
+ }),
42
42
  });
43
43
  } catch (e) {
44
44
  logError(e as string);
package/src/utils.test.ts CHANGED
@@ -1,23 +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
3
  import { AstroGlobal } from "astro";
4
4
 
5
- it("should return the current path", () => {
6
- const astro = {
7
- request: {
8
- url: "https://example.com/test",
9
- },
10
- } as AstroGlobal;
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;
11
12
 
12
- expect(getCurrentPath(astro)).toBe("/test");
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
+ });
13
25
  });
14
26
 
15
- it("should ignore query parameters", () => {
16
- const astro = {
17
- request: {
18
- url: "https://example.com/test?query=param",
19
- },
20
- } as AstroGlobal;
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);
21
42
 
22
- expect(getCurrentPath(astro)).toBe("/test");
43
+ expect(result).toEqual({
44
+ copy_confirmation_message: "Thank you for your comment!",
45
+ copy_submit_button: "Submit",
46
+ });
47
+ });
23
48
  });
package/src/utils.ts CHANGED
@@ -3,3 +3,9 @@ import { AstroGlobal } from "astro";
3
3
  export function getCurrentPath(astro: AstroGlobal) {
4
4
  return new URL(astro.request.url).pathname;
5
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
+ }