Skip to content

Commit

Permalink
Merge pull request #41 from abdouhl/master
Browse files Browse the repository at this point in the history
stringify favorite_count
  • Loading branch information
zernonia authored Sep 12, 2022
2 parents 45acdd4 + 90a0216 commit 1c2473a
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions server/_lib/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,15 @@ export const constructHtml = (data: TweetSyndication, options: TweetOptions, isQ
const tweet_class = isQuotedTweet
? mapClassOptions("tweet").replace("w-[400px]", "").replace("w-[500px]", "").concat(" mt-4")
: mapClassOptions("tweet")


let favorite_count_str;
if (meta.favorite_count >= 1000000){
favorite_count_str = (meta.favorite_count/1000000).toFixed(1)+' m';
} else if (meta.favorite_count >= 10000){
favorite_count_str = (meta.favorite_count/1000).toFixed(1)+' K';
} else {
favorite_count_str = meta.favorite_count?.toLocaleString("en-US")
}
const html: string = `
<div class="${tweet_class} " data-style="${options.layout}">
<div class="${mapClassOptions("tweet-header")}">
Expand Down Expand Up @@ -69,7 +77,7 @@ export const constructHtml = (data: TweetSyndication, options: TweetOptions, isQ
<svg class="${mapClassOptions(
"tweet-info-favourite"
)}" width="24" height="24" viewBox="0 0 24 24"><path class="fill-current" d="M12 21.638h-.014C9.403 21.59 1.95 14.856 1.95 8.478c0-3.064 2.525-5.754 5.403-5.754 2.29 0 3.83 1.58 4.646 2.73.813-1.148 2.353-2.73 4.644-2.73 2.88 0 5.404 2.69 5.404 5.755 0 6.375-7.454 13.11-10.037 13.156H12zM7.354 4.225c-2.08 0-3.903 1.988-3.903 4.255 0 5.74 7.035 11.596 8.55 11.658 1.52-.062 8.55-5.917 8.55-11.658 0-2.267-1.822-4.255-3.902-4.255-2.528 0-3.94 2.936-3.952 2.965-.23.562-1.156.562-1.387 0-.015-.03-1.426-2.965-3.955-2.965z"></path></svg>
<span>${meta.favorite_count}</span>
<span>${favorite_count_str}</span>
<div class="${mapClassOptions("tweet-info-date")}">${format(new Date(meta.created_at), "h:mm a · MMM d, y")}</div>
</div>
`
Expand Down

1 comment on commit 1c2473a

@vercel
Copy link

@vercel vercel bot commented on 1c2473a Sep 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.