gofmt + fix commits behind/ahead

This commit is contained in:
Arya Kiran
2023-06-08 15:34:43 +08:00
parent cc451e1c0e
commit d9f01b80d8
2 changed files with 26 additions and 20 deletions
+12 -10
View File
@@ -12,9 +12,9 @@ import (
)
type Languages struct {
Name string
Percent string
Color string
Name string
Percent string
Color string
}
type Repo struct {
@@ -24,8 +24,9 @@ type Repo struct {
Stars string
Forks string
CommitsBehind string
CommitsAhead string
Watchers string
Language []Languages
Language []Languages
License string
DefaultBranch string
Readme string
@@ -85,7 +86,8 @@ func HandleRepo(c *fiber.Ctx) error {
})
})
sc.OnHTML("div.Box-body div.d-flex div span", func(e *colly.HTMLElement) {
Scrape.CommitsBehind = strings.TrimSuffix(e.ChildText("a"), " commits behind")
Scrape.CommitsBehind = strings.TrimSuffix(e.ChildText("a[data-analytics-event*='Behind Compare']"), " commits behind")
Scrape.CommitsAhead = strings.TrimSuffix(e.ChildText("a[data-analytics-event*='Ahead Compare']"), " commits ahead")
})
sc.OnHTML("div#readme", func(e *colly.HTMLElement) {
Scrape.Readme = e.ChildText("a[href='#readme']")
@@ -96,11 +98,11 @@ func HandleRepo(c *fiber.Ctx) error {
})
sc.OnHTML("div.BorderGrid-cell ul.list-style-none", func(e *colly.HTMLElement) {
e.ForEach("li.d-inline .d-inline-flex", func(i int, el *colly.HTMLElement) {
var lang Languages
lang.Name = el.ChildText("span.text-bold")
lang.Percent = el.ChildText("span:contains('%')")
lang.Color = strings.ReplaceAll(strings.ReplaceAll(el.ChildAttr("svg", "style"), "color:", ""), ";", "")
Scrape.Language = append(Scrape.Language, lang)
var lang Languages
lang.Name = el.ChildText("span.text-bold")
lang.Percent = el.ChildText("span:contains('%')")
lang.Color = strings.ReplaceAll(strings.ReplaceAll(el.ChildAttr("svg", "style"), "color:", ""), ";", "")
Scrape.Language = append(Scrape.Language, lang)
})
})
sc.OnHTML("div#repository-container-header", func(e *colly.HTMLElement) {
+14 -10
View File
@@ -30,18 +30,22 @@
⭐ {{.Stars}} 🍴 {{.Forks}} 👀 {{.Watchers}} ⚖️ No license 🌿
{{.DefaultBranch}}
</p>
{{ end }} {{ if .Language }}
{{ end }} {{ if .Language }} {{range $o := .Language}}{{$o.Name}}
{{$o.Percent}}, {{end}}
<div class="lang-bar">
{{range $i, $o := .Language}}
<span style="width: {{$o.Percent}}; background-color: {{$o.Color}}">
&nbsp;
</span>
{{end}}
</div>
{{end}} {{ if or .CommitsAhead .CommitsBehind }}
<p>
{{range $o := .Language}}{{$o.Name}} {{$o.Percent}}, {{end}}
<div class="lang-bar">{{range $i, $o := .Language}}
<span style="width: {{$o.Percent}}; background-color: {{$o.Color}}">
&nbsp;
</span>
{{end}}
</div>
This repository is {{if .CommitsBehind}} {{.CommitsBehind}} commits behind {{end}} {{if and .CommitsBehind .CommitsAhead}} and {{end}}
{{if .CommitsAhead}} {{ .CommitsAhead }} commits ahead of {{end}} its
parent.
</p>
{{end}} {{ if .CommitsBehind }} This repository is {{.CommitsBehind}}
commits behind its parent. {{end}}
{{end}}
</div>
{{end}} {{ if .files}}
<div class="user-readme">