From 45644a05038aef0649755d6ef53137ff5aea92b3 Mon Sep 17 00:00:00 2001 From: httpjamesm Date: Thu, 16 Feb 2023 10:25:24 -0500 Subject: [PATCH] feat: get stackexchange posts fix: comment author distinguishing --- main.go | 9 +++++++++ src/routes/question.go | 12 ++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/main.go b/main.go index 20799be..b7bb84f 100644 --- a/main.go +++ b/main.go @@ -59,6 +59,15 @@ func main() { // redirect user to the answer with the title c.Redirect(302, fmt.Sprintf("/questions/%s/%s#%s", c.Param("id"), c.Param("title"), c.Param("answerId"))) }) + r.GET("/exchange/:sub/questions/:id/:title", routes.ViewQuestion) + r.GET("/exchange/:sub/questions/:id", func(c *gin.Context) { + // redirect user to the question with the title + c.Redirect(302, fmt.Sprintf("/exchange/%s/questions/%s/placeholder", c.Param("sub"), c.Param("id"))) + }) + r.GET("/exchange/:sub/questions/:id/:title/:answerId", func(c *gin.Context) { + // redirect user to the answer with the title + c.Redirect(302, fmt.Sprintf("/exchange/%s/questions/%s/%s#%s", c.Param("sub"), c.Param("id"), c.Param("title"), c.Param("answerId"))) + }) r.GET("/proxy", routes.GetImage) diff --git a/src/routes/question.go b/src/routes/question.go index 3b63028..0bfde6e 100644 --- a/src/routes/question.go +++ b/src/routes/question.go @@ -53,7 +53,15 @@ func ViewQuestion(c *gin.Context) { soSortValue = soSortValues["votes"] } - soLink := fmt.Sprintf("https://stackoverflow.com/questions/%s/%s?answertab=%s", questionId, questionTitle, soSortValue) + sub := c.Param("sub") + + domain := "stackoverflow.com" + + if sub != "" { + domain = fmt.Sprintf("%s.stackexchange.com", sub) + } + + soLink := fmt.Sprintf("https://%s/questions/%s/%s?answertab=%s", domain, questionId, questionTitle, soSortValue) resp, err := client.R().Get(soLink) if err != nil { @@ -218,7 +226,7 @@ func ViewQuestion(c *gin.Context) { answerTimestamp := "" answerFooter.Find("div.post-signature").Each(func(i int, s *goquery.Selection) { - questionAuthorDetails := questionMetadata.Find("div.user-details") + questionAuthorDetails := s.Find("div.user-details") if questionAuthorDetails.Length() > 0 { questionAuthor := questionAuthorDetails.Find("a").First()