feat: parse accepted answer and add tag
This commit is contained in:
parent
f1d22a713f
commit
010bd290af
6
main.go
6
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 <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))
|
||||
})
|
||||
|
||||
|
@ -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; */
|
||||
}
|
@ -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">
|
||||
@ -19,8 +23,8 @@
|
||||
<hr />
|
||||
<h2>Answers</h2>
|
||||
{{ range $answer := .answers }}
|
||||
<div class="answer">{{ $answer }}</div>
|
||||
<hr class="answer-divider" />
|
||||
<div class="answer">{{ $answer }}</div>
|
||||
<hr class="answer-divider" />
|
||||
{{ end }}
|
||||
</div>
|
||||
</body>
|
||||
|
Loading…
x
Reference in New Issue
Block a user