MCPcopy Create free account
hub / github.com/dailydotdev/apps / commentToSchema

Function commentToSchema

packages/webapp/components/PostSEOSchema.tsx:137–166  ·  view source on GitHub ↗
(
  comment: Comment,
  maxDepth = 3,
  currentDepth = 0,
)

Source from the content-addressed store, hash-verified

135 * Convert a comment to schema.org Comment format with optional nested children
136 */
137const commentToSchema = (
138 comment: Comment,
139 maxDepth = 3,
140 currentDepth = 0,
141): Record<string, unknown> => ({
142 '@type': 'Comment',
143 text: stripHtmlTags(comment.contentHtml),
144 datePublished: comment.createdAt,
145 ...(comment.lastUpdatedAt && { dateModified: comment.lastUpdatedAt }),
146 url: comment.permalink,
147 // Omit author field entirely if not present (schema.org best practice)
148 ...(comment.author && {
149 author: getPersonSchema(comment.author),
150 }),
151 // Interaction statistics for comments (upvotes)
152 ...(comment.numUpvotes > 0 && {
153 interactionStatistic: {
154 '@type': 'InteractionCounter',
155 interactionType: { '@type': 'LikeAction' },
156 userInteractionCount: comment.numUpvotes,
157 },
158 }),
159 // Recursively include nested replies (limit depth for performance)
160 ...(comment.children?.edges?.length &&
161 currentDepth < maxDepth && {
162 comment: comment.children.edges
163 .filter((edge) => edge?.node)
164 .map((edge) => commentToSchema(edge.node, maxDepth, currentDepth + 1)),
165 }),
166});
167
168/**
169 * Generate DiscussionForumPosting schema for user-generated Squad posts

Callers 2

getCommentsJsonLdFunction · 0.85

Calls 2

stripHtmlTagsFunction · 0.90
getPersonSchemaFunction · 0.85

Tested by

no test coverage detected