diff --git a/pages/repo.go b/pages/repo.go index 908b82d..8d6e844 100644 --- a/pages/repo.go +++ b/pages/repo.go @@ -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) { diff --git a/views/repo.html b/views/repo.html index ff1ff36..fbcef1c 100644 --- a/views/repo.html +++ b/views/repo.html @@ -30,18 +30,22 @@ ⭐ {{.Stars}} 🍴 {{.Forks}} 👀 {{.Watchers}} ⚖️ No license 🌿 {{.DefaultBranch}}

- {{ end }} {{ if .Language }} + {{ end }} {{ if .Language }} {{range $o := .Language}}{{$o.Name}} + {{$o.Percent}}, {{end}} +
+ {{range $i, $o := .Language}} + +   + + {{end}} +
+ {{end}} {{ if or .CommitsAhead .CommitsBehind }}

- {{range $o := .Language}}{{$o.Name}} {{$o.Percent}}, {{end}} -

{{range $i, $o := .Language}} - -   - - {{end}} -
+ This repository is {{if .CommitsBehind}} {{.CommitsBehind}} commits behind {{end}} {{if and .CommitsBehind .CommitsAhead}} and {{end}} + {{if .CommitsAhead}} {{ .CommitsAhead }} commits ahead of {{end}} its + parent.

- {{end}} {{ if .CommitsBehind }} This repository is {{.CommitsBehind}} - commits behind its parent. {{end}} + {{end}} {{end}} {{ if .files}}