レポジトリヘッダー

このコミットが含まれているのは:
守矢諏訪子 2023-06-08 00:15:22 +09:00
コミット ba97d8b78b
2個のファイルの変更53行の追加33行の削除

ファイルの表示

@ -13,38 +13,22 @@ import (
) )
type Languages struct { type Languages struct {
Name string Name, Percent, Color string
Percent string }
Color string
type LastCommit struct {
Ava, User, Id, IdShort, Mess, MessIssue, Date string
} }
type Repo struct { type Repo struct {
Username string Username, Reponame, CommitCount, Description, Parent, Stars, Forks, CommitsBehind, Watchers, License, DefaultBranch, Readme, Link, ComCount string
Reponame string Tags, Branch []string
Description string
Parent string
Stars string
Forks string
CommitsBehind string
Watchers string
Language []Languages Language []Languages
License string LastCom LastCommit
DefaultBranch string
Readme string
Link string
Tags []string
Branch []string
} }
type RepoFiles struct { type RepoFiles struct {
Name string Name, Path, Commit, Date, Type, Username, Reponame, DefaultBranch string
Path string
Commit string
Date string
Type string
Username string
Reponame string
DefaultBranch string
} }
func HandleRepo(c *fiber.Ctx) error { 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 := colly.NewCollector(colly.AllowedDomains("github.com"), colly.UserAgent(UserAgent))
sc.Limit(&colly.LimitRule{ sc.Limit(&colly.LimitRule{
DomainGlob: "github.githubassets.com/*", DomainGlob: "github.githubassets.com/*",
Delay: 15 * time.Second, Delay: 30 * time.Second,
RandomDelay: 15 * time.Second, RandomDelay: 30 * time.Second,
}) })
sc.OnHTML("div.Layout-sidebar", func(e *colly.HTMLElement) { sc.OnHTML("div.Layout-sidebar", func(e *colly.HTMLElement) {
Scrape.Username = c.Params("user") 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:")) 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) { 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"), " commits behind")
}) })
@ -158,6 +160,9 @@ func HandleRepo(c *fiber.Ctx) error {
"ver": utils.Ver, "ver": utils.Ver,
"ves": utils.Ves, "ves": utils.Ves,
"repo": repoArray, "repo": repoArray,
"usrep": c.Params("user") + "/" + repoUrl,
"commits": Scrape.ComCount,
"lastcom": Scrape.LastCom,
"files": repoFilesArray, "files": repoFilesArray,
"readme": readmeOutput, "readme": readmeOutput,
}) })

ファイルの表示

@ -42,6 +42,21 @@
<div class="user-readme"> <div class="user-readme">
<h3>ファイル</h3> <h3>ファイル</h3>
<table class="user-readme-text file-table"> <table class="user-readme-text file-table">
<thead>
<tr>
<td colspan="2">
<a href="/{{.lastcom.User}}"><img src="{{.lastcom.Ava}}" alt="{{.lastcom.User}}さんの画像" class="avatar" width="24" height="24" /></a>
<a href="/{{.usrep}}/commits?author={{.lastcom.User}}">{{.lastcom.User}}</a>
<a href="/{{.usrep}}/commit/{{.lastcom.Id}}">{{.lastcom.Mess}}</a>
{{if .lastcom.MessIssue}}(<a href="/{{.usrep}}/pull/{{.lastcom.MessIssue}}">#{{.lastcom.MessIssue}}</a>){{end}}
</td>
<td style="text-align: right;">
<a href="/{{.usrep}}/commit/{{.lastcom.Id}}">{{.lastcom.IdShort}}</a>
<a href="/{{.usrep}}/commit/{{.lastcom.Id}}">{{.lastcom.Date}}</a>
<a href="/{{.usrep}}/commits/{{.DefaultBranch}}">{{.commits}}件コミット</a>
</td>
</tr>
</thead>
<tbody> <tbody>
{{ range $key, $value := .files}} {{ range $key, $value := .files}}
<tr class="file-u-list"> <tr class="file-u-list">