mirror of
https://github.com/httpjamesm/AnonymousOverflow.git
synced 2025-05-14 05:52:54 +00:00
feat: unify comments finder, show post comments
style: show post notices in a clean layout
This commit is contained in:
parent
84ba0886cd
commit
599d23544b
3 changed files with 71 additions and 42 deletions
|
@ -42,6 +42,8 @@ func ViewQuestion(c *gin.Context) {
|
|||
|
||||
questionText := questionTextParent.Children().First().Text()
|
||||
|
||||
questionPostLayout := doc.Find("div.post-layout").First()
|
||||
|
||||
questionBodyParent := doc.Find("div.s-prose")
|
||||
|
||||
questionBodyParentHTML, err := questionBodyParent.Html()
|
||||
|
@ -49,6 +51,8 @@ func ViewQuestion(c *gin.Context) {
|
|||
panic(err)
|
||||
}
|
||||
|
||||
questionBodyParentHTML = utils.FindAndReturnComments(questionBodyParentHTML, questionPostLayout)
|
||||
|
||||
// parse any code blocks and highlight them
|
||||
answerCodeBlocks := questionCodeBlockRegex.FindAllString(questionBodyParentHTML, -1)
|
||||
for _, codeBlock := range answerCodeBlocks {
|
||||
|
@ -166,48 +170,7 @@ func ViewQuestion(c *gin.Context) {
|
|||
answerBodyHTML = strings.Replace(answerBodyHTML, codeBlock, highlightedCodeBlock, 1)
|
||||
}
|
||||
|
||||
comments := []string{}
|
||||
|
||||
commentsComponent := postLayout.Find("div.js-post-comments-component")
|
||||
|
||||
commentsList := commentsComponent.Find("div.comments")
|
||||
commentsList2 := commentsList.Find("ul.comments-list")
|
||||
|
||||
allComments := commentsList2.Find("li.comment")
|
||||
|
||||
allComments.Each(func(i int, s *goquery.Selection) {
|
||||
commentText := s.Find("div.comment-text")
|
||||
|
||||
commentBody := commentText.Find("div.comment-body")
|
||||
|
||||
commentCopy, err := commentBody.Find("span.comment-copy").Html()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
commentAuthorURL := ""
|
||||
|
||||
commentAuthor := commentBody.Find("span.comment-user")
|
||||
if commentAuthor.Length() == 0 {
|
||||
commentAuthor = commentBody.Find("a.comment-user")
|
||||
if commentAuthor.Length() == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
commentAuthorURL = commentAuthor.AttrOr("href", "")
|
||||
}
|
||||
|
||||
commentTimestamp := commentBody.Find("span.relativetime-clean").Text()
|
||||
|
||||
comment := fmt.Sprintf(`<div class="comment-parent"><div class="comment"><div class="comment-body">%s</div><div class="comment-author">Commented %s by <a href="https://stackoverflow.com%s" target="_blank" rel="noopener noreferrer">%s</a>.</div></div></div>`, commentCopy, commentTimestamp, commentAuthorURL, commentAuthor.Text())
|
||||
|
||||
comments = append(comments, comment)
|
||||
|
||||
})
|
||||
|
||||
if len(comments) > 0 {
|
||||
answerBodyHTML += fmt.Sprintf(`<details class="comments"><summary>Show <b>%d comments</b></summary><div class="comments-parent">%s</div></details>`, len(comments), strings.Join(comments, ""))
|
||||
}
|
||||
answerBodyHTML = utils.FindAndReturnComments(answerBodyHTML, postLayout)
|
||||
|
||||
answers = append(answers, template.HTML(answerBodyHTML))
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue