@jam-comments/astro 2.4.1 → 2.5.0

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 CHANGED
@@ -7,7 +7,7 @@ declare global {
7
7
  }
8
8
 
9
9
  export interface JamCommentsProps {
10
- path: string;
10
+ path?: string;
11
11
  schema?: string | object;
12
12
  domain?: string;
13
13
  apiKey?: string;
@@ -16,4 +16,4 @@ export interface JamCommentsProps {
16
16
  tz?: string;
17
17
  }
18
18
 
19
- export default function JamComments({ path }: JamCommentsProps): JSX.Element;
19
+ 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.4.1",
3
+ "version": "2.5.0",
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.",
@@ -11,7 +11,8 @@
11
11
  "scripts": {
12
12
  "build": "echo 'No build step here...'",
13
13
  "format": "prettier --write src",
14
- "check": "astro check"
14
+ "check": "astro check",
15
+ "test": "vitest run"
15
16
  },
16
17
  "files": [
17
18
  "src",
@@ -45,7 +46,9 @@
45
46
  },
46
47
  "gitHead": "2b1cefb90c89a2f70099213881b09216f20e3dc2",
47
48
  "devDependencies": {
49
+ "@types/node": "^20.12.12",
48
50
  "prettier": "^3.2.5",
49
- "prettier-plugin-astro": "^0.13.0"
51
+ "prettier-plugin-astro": "^0.13.0",
52
+ "vitest": "^1.6.0"
50
53
  }
51
54
  }
@@ -2,13 +2,14 @@
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
6
  const { logError, markupFetcher } = pkg;
6
7
 
7
8
  type Props = JamCommentsProps;
8
9
 
9
10
  const fetchMarkup = markupFetcher("astro", nodeFetch as any);
10
11
 
11
- const fetchCommentData = async ({
12
+ async function fetchCommentData({
12
13
  tz = undefined,
13
14
  path = undefined,
14
15
  schema = undefined,
@@ -16,7 +17,7 @@ const fetchCommentData = async ({
16
17
  apiKey = import.meta.env.JAM_COMMENTS_API_KEY as string,
17
18
  baseUrl = import.meta.env.JAM_COMMENTS_BASE_URL as string,
18
19
  environment = import.meta.env.JAM_COMMENTS_ENVIRONMENT as string,
19
- }: JamCommentsProps) => {
20
+ }: JamCommentsProps) {
20
21
  try {
21
22
  return await fetchMarkup({
22
23
  path,
@@ -31,11 +32,12 @@ const fetchCommentData = async ({
31
32
  logError(e as string);
32
33
  return null;
33
34
  }
34
- };
35
+ }
35
36
 
36
37
  const { path, domain, baseUrl, environment, tz, schema } = Astro.props as Props;
38
+
37
39
  const markup = await fetchCommentData({
38
- path,
40
+ path: path || getCurrentPath(Astro),
39
41
  schema,
40
42
  domain,
41
43
  baseUrl,
@@ -0,0 +1,22 @@
1
+ import { expect, it } from "vitest";
2
+ import { getCurrentPath } from "./utils";
3
+
4
+ it("should return the current path", () => {
5
+ const astro = {
6
+ request: {
7
+ url: "https://example.com/test",
8
+ },
9
+ };
10
+
11
+ expect(getCurrentPath(astro)).toBe("/test");
12
+ });
13
+
14
+ it("should ignore query parameters", () => {
15
+ const astro = {
16
+ request: {
17
+ url: "https://example.com/test?query=param",
18
+ },
19
+ };
20
+
21
+ expect(getCurrentPath(astro)).toBe("/test");
22
+ });
package/src/utils.ts ADDED
@@ -0,0 +1,3 @@
1
+ export function getCurrentPath(astro) {
2
+ return new URL(astro.request.url).pathname;
3
+ }