feat: get answers and iterate over them

This commit is contained in:
httpjamesm 2022-12-27 22:50:38 -05:00
parent b7345d39a0
commit f1d22a713f
3 changed files with 27 additions and 0 deletions

10
main.go
View File

@ -96,12 +96,22 @@ func main() {
}
})
answers := []template.HTML{}
doc.Find("div.answer").Each(func(i int, s *goquery.Selection) {
postLayout := s.Find("div.post-layout")
answerCell := postLayout.Find("div.answercell")
answerBody := answerCell.Find("div.s-prose")
answerBodyHTML, _ := answerBody.Html()
answers = append(answers, template.HTML(answerBodyHTML))
})
c.HTML(200, "question.html", gin.H{
"title": questionText,
"body": template.HTML(questionBodyParentHTML),
"timestamp": questionTimestamp,
"author": questionAuthor,
"authorURL": questionAuthorURL,
"answers": answers,
})
})

View File

@ -30,6 +30,11 @@ body {
box-sizing: border-box;
}
.parent {
max-width: 90%;
width: fit-content;
}
code {
background-color: var(--code-bg);
padding: .15rem;
@ -55,3 +60,11 @@ pre {
a {
color: #92adff;
}
.answer-divider {
margin-top: 3rem;
margin-bottom: 3rem;
border: 0;
height: 1px;
background-color: #42464e;
}

View File

@ -18,6 +18,10 @@
</div>
<hr />
<h2>Answers</h2>
{{ range $answer := .answers }}
<div class="answer">{{ $answer }}</div>
<hr class="answer-divider" />
{{ end }}
</div>
</body>
</html>