diff --git a/pages/repo.go b/pages/repo.go index 241445c..e0543d0 100644 --- a/pages/repo.go +++ b/pages/repo.go @@ -13,38 +13,22 @@ import ( ) type Languages struct { - Name string - Percent string - Color string + Name, Percent, Color string +} + +type LastCommit struct { + Ava, User, Id, IdShort, Mess, MessIssue, Date string } type Repo struct { - Username string - Reponame string - Description string - Parent string - Stars string - Forks string - CommitsBehind string - Watchers string + Username, Reponame, CommitCount, Description, Parent, Stars, Forks, CommitsBehind, Watchers, License, DefaultBranch, Readme, Link, ComCount string + Tags, Branch []string Language []Languages - License string - DefaultBranch string - Readme string - Link string - Tags []string - Branch []string + LastCom LastCommit } type RepoFiles struct { - Name string - Path string - Commit string - Date string - Type string - Username string - Reponame string - DefaultBranch string + Name, Path, Commit, Date, Type, Username, Reponame, DefaultBranch string } func HandleRepo(c *fiber.Ctx) error { @@ -81,8 +65,8 @@ func HandleRepo(c *fiber.Ctx) error { sc := colly.NewCollector(colly.AllowedDomains("github.com"), colly.UserAgent(UserAgent)) sc.Limit(&colly.LimitRule{ DomainGlob: "github.githubassets.com/*", - Delay: 15 * time.Second, - RandomDelay: 15 * time.Second, + Delay: 30 * time.Second, + RandomDelay: 30 * time.Second, }) sc.OnHTML("div.Layout-sidebar", func(e *colly.HTMLElement) { Scrape.Username = c.Params("user") @@ -97,6 +81,24 @@ func HandleRepo(c *fiber.Ctx) error { Scrape.Tags = append(Scrape.Tags, strings.TrimPrefix(el.Attr("data-octo-dimensions"), "topic:")) }) }) + sc.OnHTML("div.Box-header div.js-details-container", func(e *colly.HTMLElement) { + var commit LastCommit + commit.Ava = strings.ReplaceAll(e.ChildAttr("img", "src"), "https://avatars.githubusercontent.com/u", "/avatar") + commit.User = e.ChildText("a.commit-author") + commit.Id = strings.TrimPrefix(e.ChildAttr("a.Link--primary", "href"), "/" + c.Params("user") + "/" + repoUrl + "/commit/") + commit.IdShort = e.ChildText("div.flex-items-baseline a.f6") + commit.Mess = e.ChildText("span.d-none a.Link--primary") + Scrape.ComCount = e.ChildText("li.ml-0 a.Link--primary span.d-none strong") + commit.MessIssue = strings.ReplaceAll(e.ChildText("span.d-none a.issue-link"), "#", "") + tstring := e.ChildAttr("relative-time", "datetime") + if tstring != "" { + tstring = strings.Split(tstring, "T")[0] + tstrings := strings.Split(tstring, "-") + tstring = tstrings[0] + "-" + tstrings[1] + "-" + tstrings[2] + } + commit.Date = tstring + Scrape.LastCom = commit + }) sc.OnHTML("div.Box-body div.d-flex div span", func(e *colly.HTMLElement) { Scrape.CommitsBehind = strings.TrimSuffix(e.ChildText("a"), " commits behind") }) @@ -154,11 +156,14 @@ func HandleRepo(c *fiber.Ctx) error { // Add scrape-based info to repoArray repoArray = append(repoArray, Scrape) return c.Render("repo", fiber.Map{ - "title": c.Params("user") + "/" + repoUrl + branchExists, - "ver": utils.Ver, - "ves": utils.Ves, - "repo": repoArray, - "files": repoFilesArray, - "readme": readmeOutput, + "title": c.Params("user") + "/" + repoUrl + branchExists, + "ver": utils.Ver, + "ves": utils.Ves, + "repo": repoArray, + "usrep": c.Params("user") + "/" + repoUrl, + "commits": Scrape.ComCount, + "lastcom": Scrape.LastCom, + "files": repoFilesArray, + "readme": readmeOutput, }) } diff --git a/views/repo.html b/views/repo.html index 12a61fa..243750d 100644 --- a/views/repo.html +++ b/views/repo.html @@ -42,6 +42,21 @@

ファイル

+ + + + + + {{ range $key, $value := .files}}
+ {{.lastcom.User}}さんの画像 + {{.lastcom.User}} + {{.lastcom.Mess}} + {{if .lastcom.MessIssue}}(#{{.lastcom.MessIssue}}){{end}} + + {{.lastcom.IdShort}} + {{.lastcom.Date}} + {{.commits}}件コミット +