feat: get timestamp and author details
This commit is contained in:
parent
60f0ec5ce9
commit
b7345d39a0
52
main.go
52
main.go
@ -51,9 +51,57 @@ func main() {
|
|||||||
panic(err)
|
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{
|
c.HTML(200, "question.html", gin.H{
|
||||||
"title": questionText,
|
"title": questionText,
|
||||||
"body": template.HTML(questionBodyParentHTML),
|
"body": template.HTML(questionBodyParentHTML),
|
||||||
|
"timestamp": questionTimestamp,
|
||||||
|
"author": questionAuthor,
|
||||||
|
"authorURL": questionAuthorURL,
|
||||||
})
|
})
|
||||||
|
|
||||||
})
|
})
|
||||||
|
@ -43,4 +43,15 @@ pre {
|
|||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
color: white;
|
color: white;
|
||||||
overflow-x: auto;
|
overflow-x: auto;
|
||||||
|
line-height: 1.35;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
.timestamp {
|
||||||
|
color: #b3b3b3;
|
||||||
|
font-size: 0.8rem;
|
||||||
|
}
|
||||||
|
|
||||||
|
a {
|
||||||
|
color: #92adff;
|
||||||
|
}
|
@ -2,19 +2,22 @@
|
|||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>{{ .title }}</title>
|
<title>{{ .title }}</title>
|
||||||
<link rel="stylesheet" href="/static/question.css">
|
<link rel="stylesheet" href="/static/question.css" />
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="parent">
|
<div class="parent">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
<h1>{{ .title }}</h1>
|
<h1>{{ .title }}</h1>
|
||||||
|
<p class="timestamp">
|
||||||
|
Asked {{ .timestamp }} by
|
||||||
|
<a href="{{ .authorURL }}">{{ .author }}</a>.
|
||||||
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-body">
|
<div class="card-body">{{ .body }}</div>
|
||||||
{{ .body }}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
<hr />
|
||||||
|
<h2>Answers</h2>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user