Skip to content

Commit b8e9b9b

Browse files
committed
fix: jsonld base url
1 parent b222884 commit b8e9b9b

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

packages/ui/src/pages/widget/page-url.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,17 @@ export function CommentWidgetPage(props: PageCommentProps): JSX.Element {
8888
);
8989
}
9090

91+
const jsonldUrl = `https://chirpy.dev/widget/comment/${encodeURIComponent(
92+
props.page.url,
93+
)}`;
9194
// Create JSON-LD structured data for the comments
9295
const jsonLdData: WithContext<DiscussionForumPosting> = {
9396
'@context': 'https://schema.org',
9497
'@type': 'DiscussionForumPosting',
95-
url: props.page.url,
98+
headline: `Comments on ${props.page.url} - Powered by Chirpy`,
99+
url: jsonldUrl,
96100
comment: [...comments, ...pinnedComments].map((comment: ForestComment) =>
97-
createCommentJsonLd(comment, props.page.url),
101+
createCommentJsonLd(comment, jsonldUrl),
98102
) as Comment[],
99103
};
100104

packages/ui/src/pages/widget/timeline.tsx

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -33,23 +33,21 @@ type TimelineComment = NonNullable<RouterOutputs['comment']['timeline']>;
3333
/**
3434
* Creates a JSON-LD comment structure recursively for a comment and its replies
3535
*/
36-
function createCommentJsonLd(
37-
comment: TimelineComment,
38-
pageUrl: string,
39-
): Comment | null {
36+
function createCommentJsonLd(comment: TimelineComment): Comment | null {
4037
const author: Person = {
4138
'@type': 'Person',
4239
name: comment.user.name || '',
4340
image: comment.user.image || undefined,
4441
};
4542

43+
const jsonldUrl = `https://chirpy.dev/widget/comment/timeline/${comment.id}`;
4644
const commentJsonLd: Comment = {
4745
'@type': 'Comment',
4846
text: getTextFromRteValue(comment.content as RTEValue),
4947
dateCreated: comment.createdAt.toISOString(),
5048
author: author,
51-
url: `${pageUrl}#comment-${comment.id}`,
52-
mainEntityOfPage: pageUrl,
49+
url: jsonldUrl,
50+
mainEntityOfPage: jsonldUrl,
5351
};
5452

5553
// Add likes information if available
@@ -65,14 +63,14 @@ function createCommentJsonLd(
6563
if (comment.parentId) {
6664
commentJsonLd.parentItem = {
6765
'@type': 'Comment',
68-
url: `${pageUrl}#comment-${comment.parentId}`,
66+
url: `https://chirpy.dev/widget/comment/timeline/${comment.parentId}`,
6967
} as Comment;
7068
}
7169

7270
// Recursively process replies (if they exist in the timeline data)
7371
if (comment.replies && comment.replies.length > 0) {
7472
commentJsonLd.comment = comment.replies
75-
.map((reply: any) => createCommentJsonLd(reply, pageUrl))
73+
.map((reply: any) => createCommentJsonLd(reply))
7674
.filter(Boolean) as Comment[];
7775
}
7876

@@ -93,9 +91,7 @@ export function CommentTimelineWidget(
9391
);
9492

9593
// Generate JSON-LD data for the comment timeline
96-
const jsonLdData = comment
97-
? createCommentJsonLd(comment, props.page.url)
98-
: null;
94+
const jsonLdData = comment ? createCommentJsonLd(comment) : null;
9995

10096
return (
10197
<WidgetLayout widgetTheme={props.theme} title="Comment timeline">

0 commit comments

Comments
 (0)