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