( comment: Comment, maxDepth = 3, currentDepth = 0, )
| 135 | * Convert a comment to schema.org Comment format with optional nested children |
| 136 | */ |
| 137 | const 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 |
no test coverage detected