diff --git a/main.go b/main.go index fe524d5..a64521c 100644 --- a/main.go +++ b/main.go @@ -51,9 +51,57 @@ func main() { panic(err) } + questionCard := doc.Find("div.postcell") + + questionMetadata := questionCard.Find("div.user-info") + questionTimestamp := "" + questionMetadata.Find("span.relativetime").Each(func(i int, s *goquery.Selection) { + // get the second + if i == 0 { + if s.Text() != "" { + // if it's not been edited, it means it's the first + questionTimestamp = s.Text() + return + } + } + + // otherwise it's the second element + if i == 1 { + questionTimestamp = s.Text() + return + } + }) + + userDetails := questionMetadata.Find("div.user-details") + + questionAuthor := "" + questionAuthorURL := "" + + userDetails.Find("a").Each(func(i int, s *goquery.Selection) { + // get the second + if i == 0 { + if s.Text() != "" { + // if it's not been edited, it means it's the first + questionAuthor = s.Text() + questionAuthorURL, _ = s.Attr("href") + return + } + } + + // otherwise it's the second element + if i == 1 { + questionAuthor = s.Text() + questionAuthorURL, _ = s.Attr("href") + return + } + }) + c.HTML(200, "question.html", gin.H{ - "title": questionText, - "body": template.HTML(questionBodyParentHTML), + "title": questionText, + "body": template.HTML(questionBodyParentHTML), + "timestamp": questionTimestamp, + "author": questionAuthor, + "authorURL": questionAuthorURL, }) }) diff --git a/public/question.css b/public/question.css index 462f173..168bd0b 100644 --- a/public/question.css +++ b/public/question.css @@ -43,4 +43,15 @@ pre { border-radius: 5px; color: white; overflow-x: auto; + line-height: 1.35; } + + +.timestamp { + color: #b3b3b3; + font-size: 0.8rem; +} + +a { + color: #92adff; +} \ No newline at end of file diff --git a/templates/question.html b/templates/question.html index 87ba1a2..64bbba0 100644 --- a/templates/question.html +++ b/templates/question.html @@ -2,19 +2,22 @@ {{ .title }} - +

{{ .title }}

+

+ Asked {{ .timestamp }} by + {{ .author }}. +

-
- {{ .body }} -
+
{{ .body }}
+
+

Answers

-