From 010bd290afa643fb97b0d67b65b483bb746aac06 Mon Sep 17 00:00:00 2001 From: httpjamesm Date: Tue, 27 Dec 2022 23:00:54 -0500 Subject: [PATCH] feat: parse accepted answer and add tag --- main.go | 6 ++++++ public/question.css | 13 +++++++++++++ templates/question.html | 8 ++++++-- 3 files changed, 25 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index a27bbd6..944a582 100644 --- a/main.go +++ b/main.go @@ -97,11 +97,17 @@ 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() + if s.HasClass("accepted-answer") { + // add
Accepted Answer
to the top of the answer + answerBodyHTML = `
Accepted Answer
` + answerBodyHTML + } + answers = append(answers, template.HTML(answerBodyHTML)) }) diff --git a/public/question.css b/public/question.css index 8cf82b2..d01810d 100644 --- a/public/question.css +++ b/public/question.css @@ -67,4 +67,17 @@ a { border: 0; height: 1px; background-color: #42464e; +} + +img { + max-width: 100%; +} + +.accepted-answer { + background-color: #8cffc0; + border-radius: 5px; + padding: 1rem; + color: black; + margin-bottom: 1rem; + /* width: fit-content; */ } \ No newline at end of file diff --git a/templates/question.html b/templates/question.html index 876c957..56660ba 100644 --- a/templates/question.html +++ b/templates/question.html @@ -3,6 +3,10 @@ {{ .title }} +
@@ -19,8 +23,8 @@

Answers

{{ range $answer := .answers }} -
{{ $answer }}
-
+
{{ $answer }}
+
{{ end }}