Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stringify favorite_count #41

Merged
merged 5 commits into from
Sep 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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