diff --git a/pages/repo.go b/pages/repo.go index 1becc83..46ee460 100644 --- a/pages/repo.go +++ b/pages/repo.go @@ -19,7 +19,7 @@ type Repo struct { Stars string Forks string Watchers string - Language string + Language []string License string DefaultBranch string Readme string @@ -63,9 +63,7 @@ func HandleRepo(c *fiber.Ctx) error { } // Scraping - Scrape := Repo{ - Language: repo.Get("language").String(), - } + Scrape := Repo{} UserAgent, ok := os.LookupEnv("GOTHUB_USER_AGENT") if !ok { @@ -84,6 +82,11 @@ func HandleRepo(c *fiber.Ctx) error { sc.OnHTML("div#readme", func(e *colly.HTMLElement) { Scrape.Readme = e.ChildText("a[href*='#readme']") }) + 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) { + Scrape.Language = append(Scrape.Language, el.ChildText("span.text-bold")+" "+el.ChildText("span:contains('%')")) + }) + }) sc.OnHTML("div#repository-container-header", func(e *colly.HTMLElement) { Scrape.Parent = e.ChildText("span.text-small a") }) @@ -92,7 +95,6 @@ func HandleRepo(c *fiber.Ctx) error { }) sc.Visit("https://github.com/" + c.Params("user") + "/" + c.Params("repo") + "/") - // Add scrape-based info to repoArray repoArray = append(repoArray, Scrape) diff --git a/views/repo.html b/views/repo.html index 8e145d9..66188e0 100644 --- a/views/repo.html +++ b/views/repo.html @@ -17,10 +17,17 @@

{{.Description}}

{{ end }} {{ if .License }} -

⭐ {{.Stars}} 🍴 {{.Forks}} 👀 {{.Watchers}} ⚖️ {{.License}} {{ if .Language }} 🗒️ {{.Language}} {{end}} 🌿 {{.DefaultBranch}}

+

⭐ {{.Stars}} 🍴 {{.Forks}} 👀 {{.Watchers}} ⚖️ {{.License}} 🌿 {{.DefaultBranch}}

{{ else }} -

⭐ {{.Stars}} 🍴 {{.Forks}} 👀 {{.Watchers}} ⚖️ No license {{ if .Language }} 🗒️ {{.Language}} {{end}} 🌿 {{.DefaultBranch}}

+

⭐ {{.Stars}} 🍴 {{.Forks}} 👀 {{.Watchers}} ⚖️ No license 🌿 {{.DefaultBranch}}

{{ end }} + {{ if .Language }} +

🗒️ + {{range .Language}} + {{.}} + {{end}} +

+ {{end}} {{end}} {{ if .files}}