feat: parse accepted answer and add tag

This commit is contained in:
httpjamesm 2022-12-27 23:00:54 -05:00
parent f1d22a713f
commit 010bd290af
3 changed files with 25 additions and 2 deletions

View File

@ -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 <div class="accepted-answer">Accepted Answer</div> to the top of the answer
answerBodyHTML = `<div class="accepted-answer">Accepted Answer</div>` + answerBodyHTML
}
answers = append(answers, template.HTML(answerBodyHTML))
})

View File

@ -68,3 +68,16 @@ a {
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; */
}

View File

@ -3,6 +3,10 @@
<head>
<title>{{ .title }}</title>
<link rel="stylesheet" href="/static/question.css" />
<meta
http-equiv="Content-Security-Policy"
content="default-src 'self'; style-src 'self'; script-src 'none'; img-src https:;"
/>
</head>
<body>
<div class="parent">