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

Function buildCommunityTake

packages/webapp/lib/postMarkdown.ts:344–465  ·  view source on GitHub ↗
(post: PostMarkdownPost)

Source from the content-addressed store, hash-verified

342};
343
344const buildCommunityTake = (post: PostMarkdownPost): string[] => {
345 const take = post.communitySentiment;
346
347 if (!take) {
348 return [];
349 }
350
351 const lines = ['## Community take', ''];
352 const { breakdown, discussions, sources, updatedAt } = take;
353
354 const totalComments =
355 discussions?.reduce((total, item) => total + item.commentsCount, 0) ?? 0;
356 const volume = [
357 `${take.postCount} discussion${take.postCount === 1 ? '' : 's'}`,
358 totalComments > 0 ? `${totalComments} comments` : undefined,
359 ]
360 .filter(Boolean)
361 .join(' and ');
362 const across = sources?.length ? ` across ${sources.join(', ')}` : '';
363 const asOf = updatedAt ? ` (as of ${updatedAt.slice(0, 10)})` : '';
364
365 lines.push(
366 `How the wider developer community reacted, aggregated from ${volume}${across}${asOf}.`,
367 );
368 lines.push('');
369
370 if (take.tldr?.trim()) {
371 lines.push(`**TL;DR:** ${take.tldr.trim()}`);
372 lines.push('');
373 }
374
375 if (breakdown) {
376 lines.push(
377 `**Sentiment:** ${formatPercentage(
378 breakdown.positive,
379 )} positive · ${formatPercentage(
380 breakdown.mixed,
381 )} mixed · ${formatPercentage(breakdown.critical)} skeptical`,
382 );
383 lines.push('');
384 }
385
386 if (take.pros?.length) {
387 lines.push('**The case for**');
388 lines.push('');
389 take.pros.forEach((pro) => lines.push(`- ${pro}`));
390 lines.push('');
391 }
392
393 if (take.cons?.length) {
394 lines.push('**The pushback**');
395 lines.push('');
396 take.cons.forEach((con) => lines.push(`- ${con}`));
397 lines.push('');
398 }
399
400 if (take.bySource?.length) {
401 lines.push('**By community**');

Callers 1

buildPostMarkdownFunction · 0.85

Calls 4

escapeMarkdownFunction · 0.90
formatPercentageFunction · 0.85
pushMethod · 0.80
replaceMethod · 0.80

Tested by

no test coverage detected