feat: display comment upvotes

This commit is contained in:
httpjamesm 2022-12-30 18:11:59 -05:00
parent 89d8dee958
commit d49c0f2ffd
5 changed files with 30 additions and 3 deletions

View File

@ -117,13 +117,25 @@ img {
cursor: text; cursor: text;
} }
.comment-top {
display: flex;
}
.comment-score {
border-right: 1px solid white;
padding-right: .5rem;
}
.comment-body { .comment-body {
font-size: 0.95rem; font-size: 0.95rem;
padding-left: .5rem;
} }
.comment-author { .comment-author {
color: var(--muted-text-color); color: var(--muted-text-color);
font-size: 0.8rem; font-size: 0.8rem;
padding-left: 1.5rem;
margin-top: .25rem;
} }
.s-notice { .s-notice {

View File

@ -7,4 +7,5 @@ type FilteredComment struct {
Timestamp string Timestamp string
AuthorName string AuthorName string
AuthorURL string AuthorURL string
Upvotes string
} }

View File

@ -17,6 +17,14 @@ func FindAndReturnComments(inHtml string, postLayout *goquery.Selection) (commen
allComments := commentsList2.Find("li.comment") allComments := commentsList2.Find("li.comment")
allComments.Each(func(i int, s *goquery.Selection) { allComments.Each(func(i int, s *goquery.Selection) {
commentScoreParent := s.Find("div.comment-score")
// find the first span within commentScoreParent
commentScore := commentScoreParent.Find("span").First().Text()
if commentScore == "" {
commentScore = "0"
}
commentText := s.Find("div.comment-text") commentText := s.Find("div.comment-text")
commentBody := commentText.Find("div.comment-body") commentBody := commentText.Find("div.comment-body")
@ -45,6 +53,7 @@ func FindAndReturnComments(inHtml string, postLayout *goquery.Selection) (commen
Timestamp: commentTimestamp, Timestamp: commentTimestamp,
AuthorName: commentAuthor.Text(), AuthorName: commentAuthor.Text(),
AuthorURL: commentAuthorURL, AuthorURL: commentAuthorURL,
Upvotes: commentScore,
} }
comments = append(comments, newFilteredComment) comments = append(comments, newFilteredComment)

View File

@ -6,8 +6,13 @@
{{ range $comment := .Comments }} {{ range $comment := .Comments }}
<div class="comment-parent"> <div class="comment-parent">
<div class="comment"> <div class="comment">
<div class="comment-body"> <div class="comment-top">
{{ $comment.Text }} <div class="comment-score" title="Comment Upvotes">
{{ $comment.Upvotes }}
</div>
<div class="comment-body">
{{ $comment.Text }}
</div>
</div> </div>
<div class="comment-author"> <div class="comment-author">
Commented {{ $comment.Timestamp }} by Commented {{ $comment.Timestamp }} by

View File

@ -21,7 +21,7 @@
alt="4 circles with alternating colors between green and white" alt="4 circles with alternating colors between green and white"
/> />
</a> </a>
{{ template "themeSwitcher.html" .}} {{ template "themeSwitcher.html" . }}
</div> </div>
<div class="card"> <div class="card">
<div class="card-header"> <div class="card-header">