From 64302c9334f5565d44886297c6c7b45998dca1d7 Mon Sep 17 00:00:00 2001 From: httpjamesm Date: Tue, 14 Feb 2023 20:13:24 -0500 Subject: [PATCH] refactor: simplify author parsing logic --- src/routes/question.go | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/routes/question.go b/src/routes/question.go index d9ad33b..775f5d5 100644 --- a/src/routes/question.go +++ b/src/routes/question.go @@ -217,22 +217,14 @@ func ViewQuestion(c *gin.Context) { answerTimestamp := "" answerFooter.Find("div.post-signature").Each(func(i int, s *goquery.Selection) { - answerAuthorDetails := s.Find("div.user-details") + questionAuthorDetails := questionMetadata.Find("div.user-details") - if answerAuthorDetails.Length() == 0 { - return + if questionAuthorDetails.Length() > 0 { + questionAuthor := questionAuthorDetails.Find("a").First() + newFilteredQuestion.AuthorName = html.EscapeString(questionAuthor.Text()) + newFilteredQuestion.AuthorURL = html.EscapeString(questionAuthor.AttrOr("href", "")) } - if answerAuthorDetails.Length() > 1 { - if i == 0 { - return - } - } - - answerAuthor := answerAuthorDetails.Find("a").First() - - answerAuthorURL = html.EscapeString(answerAuthor.AttrOr("href", "")) - answerAuthorName = html.EscapeString(answerAuthor.Text()) answerTimestamp = html.EscapeString(s.Find("span.relativetime").Text()) })