(comments: Comment[])
| 465 | }; |
| 466 | |
| 467 | const buildComments = (comments: Comment[]): string[] => { |
| 468 | const usable = comments |
| 469 | .map((comment) => ({ comment, body: comment.content?.trim() ?? '' })) |
| 470 | .filter(({ body }) => !!body); |
| 471 | |
| 472 | if (!usable.length) { |
| 473 | return []; |
| 474 | } |
| 475 | |
| 476 | const lines = [ |
| 477 | '## Community discussion', |
| 478 | '', |
| 479 | 'Top comments from developers on daily.dev.', |
| 480 | '', |
| 481 | ]; |
| 482 | |
| 483 | usable.forEach(({ comment, body }) => { |
| 484 | const handle = comment.author?.username |
| 485 | ? `@${comment.author.username}` |
| 486 | : comment.author?.name || 'A daily.dev member'; |
| 487 | lines.push( |
| 488 | `**${escapeMarkdown(handle)}** · ${comment.numUpvotes ?? 0} upvotes`, |
| 489 | ); |
| 490 | lines.push(''); |
| 491 | truncateAtWordBoundary(body, MAX_COMMENT_LENGTH) |
| 492 | .split('\n') |
| 493 | .forEach((line) => lines.push(`> ${line}`.trimEnd())); |
| 494 | lines.push(''); |
| 495 | }); |
| 496 | |
| 497 | return lines; |
| 498 | }; |
| 499 | |
| 500 | const buildSimilarPosts = (posts: SimilarPost[]): string[] => { |
| 501 | if (!posts.length) { |
no test coverage detected