feat: question tags

This commit is contained in:
httpjamesm 2023-02-04 13:40:57 -05:00
parent c87ce26da8
commit 69d96d646d
No known key found for this signature in database
5 changed files with 37 additions and 1 deletions

View File

@ -29,6 +29,20 @@ body {
justify-content: space-between;
}
.card-tags {
display: flex;
gap: .5rem;
}
.card-tags .tag {
background-color: var(--meta-bg);
color: var(--tag-text-color);
padding: 0.5rem;
border-radius: 5px;
font-size: 0.8rem;
text-decoration: none;
}
code {
background-color: var(--code-bg);
padding: 0.15rem;
@ -123,7 +137,7 @@ img {
.answers-header .sorting form {
display: flex;
align-items: center;
gap: .5rem;
gap: 0.5rem;
}
.answers-header select {

View File

@ -98,6 +98,9 @@ func ViewQuestion(c *gin.Context) {
questionPostLayout := doc.Find("div.post-layout").First()
questionTags := utils.GetPostTags(questionPostLayout)
newFilteredQuestion.Tags = questionTags
questionBodyParent := doc.Find("div.s-prose")
questionBodyParentHTML, err := questionBodyParent.Html()

View File

@ -10,4 +10,5 @@ type FilteredQuestion struct {
AuthorURL string
ShortenedBody string
Comments []FilteredComment
Tags []string
}

13
src/utils/tags.go Normal file
View File

@ -0,0 +1,13 @@
package utils
import (
"github.com/PuerkitoBio/goquery"
)
func GetPostTags(postLayout *goquery.Selection) []string {
var tags []string
postLayout.Find("a.post-tag").Each(func(i int, s *goquery.Selection) {
tags = append(tags, s.Text())
})
return tags
}

View File

@ -38,6 +38,11 @@
</p>
</div>
<div class="card-body">{{ .question.Body }}</div>
<div class="card-tags">
{{ range .question.Tags }}
<div class="tag">{{ . }}</div>
{{ end }}
</div>
{{ if .question.Comments }} {{ template "comments.html"
.question }} {{end}}
</div>