diff --git a/pages/user.go b/pages/user.go index 54854d9..f72ee2f 100644 --- a/pages/user.go +++ b/pages/user.go @@ -34,6 +34,16 @@ type User struct { Type string Contributions string Readme string + MainRepos []RepoList +} +type RepoList struct { + Name string + Type string + Desc string + Lang string + Stars string + Forks string + ForkOf string } // HandleUser handles the user page. @@ -72,7 +82,7 @@ func HandleUser(c *fiber.Ctx) error { } sc1 := colly.NewCollector(colly.AllowedDomains("github.com"), colly.UserAgent(UserAgent)) - sc1.OnHTML("div[itemtype]", func(e *colly.HTMLElement) { + sc1.OnHTML("div[itemscope]", func(e *colly.HTMLElement) { Scrape.Type = e.Attr("itemtype") }) @@ -108,7 +118,7 @@ func HandleUser(c *fiber.Ctx) error { sc.OnHTML("div.js-yearly-contributions", func(e *colly.HTMLElement) { Scrape.Contributions = e.ChildText("h2") }) - } else if Scrape.Type == "http://schema.org/Organization" { + } else if Scrape.Type == "http://schema.org/Code" { sc.OnHTML("div.container-xl div.flex-md-items-center div.flex-1", func(e *colly.HTMLElement) { // Main info Scrape.Name = e.ChildText("h1.h2") @@ -138,6 +148,20 @@ func HandleUser(c *fiber.Ctx) error { "error": "User " + c.Params("user") + " not found", }) } + sc.OnHTML("div.js-pinned-items-reorder-container", func(e *colly.HTMLElement) { + e.ForEach("div.pinned-item-list-item-content", func(i int, el *colly.HTMLElement) { + var MainRepo RepoList + MainRepo = RepoList{} // Clear data if old data is present + MainRepo.Name = el.ChildAttr("div.width-full a", "href") + MainRepo.Type = el.ChildText("div.width-full span.Label") + MainRepo.Desc = el.ChildText("p.pinned-item-desc") + MainRepo.Lang = el.ChildText("p.color-fg-muted span[itemprop*='programmingLanguage']") + MainRepo.Stars = el.ChildText("p.color-fg-muted a[href*='/stargazers' i]") + MainRepo.Forks = el.ChildText("p.color-fg-muted a[href*='/forks' i]") + MainRepo.ForkOf = el.ChildText("p.text-small a.Link--muted") + Scrape.MainRepos = append(Scrape.MainRepos, MainRepo) + }) + }) sc.Visit("https://github.com/" + c.Params("user") + "/") // Fixing the output a bit Scrape.AvatarUrl = strings.TrimPrefix(Scrape.AvatarUrl, "https://avatars.githubusercontent.com/u/")