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{}
|
answers := []template.HTML{}
|
||||||
|
|
||||||
doc.Find("div.answer").Each(func(i int, s *goquery.Selection) {
|
doc.Find("div.answer").Each(func(i int, s *goquery.Selection) {
|
||||||
postLayout := s.Find("div.post-layout")
|
postLayout := s.Find("div.post-layout")
|
||||||
answerCell := postLayout.Find("div.answercell")
|
answerCell := postLayout.Find("div.answercell")
|
||||||
answerBody := answerCell.Find("div.s-prose")
|
answerBody := answerCell.Find("div.s-prose")
|
||||||
answerBodyHTML, _ := answerBody.Html()
|
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))
|
answers = append(answers, template.HTML(answerBodyHTML))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -68,3 +68,16 @@ a {
|
|||||||
height: 1px;
|
height: 1px;
|
||||||
background-color: #42464e;
|
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>
|
<head>
|
||||||
<title>{{ .title }}</title>
|
<title>{{ .title }}</title>
|
||||||
<link rel="stylesheet" href="/static/question.css" />
|
<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>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="parent">
|
<div class="parent">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user