フォルダ表示をテーブル化、及びコミメと日時をきっと表示する様に

このコミットが含まれているのは:
守矢諏訪子 2023-06-07 11:23:35 +09:00
コミット 976a3b946a
3個のファイルの変更49行の追加16行の削除

ファイルの表示

@ -5,6 +5,7 @@ import (
"net/http" "net/http"
"os" "os"
"strings" "strings"
"time"
"gitler.moe/suwako/gitlin/utils" "gitler.moe/suwako/gitlin/utils"
"github.com/gocolly/colly" "github.com/gocolly/colly"
@ -13,7 +14,8 @@ import (
type Dir struct { type Dir struct {
Readme string Readme string
Fullname string Username string
Reponame string
DirName string DirName string
Branch string Branch string
} }
@ -21,9 +23,12 @@ type Dir struct {
type DirFiles struct { type DirFiles struct {
Name string Name string
Path string Path string
Commit string
Date string
Type string Type string
Branch string Branch string
Fullname string Username string
Reponame string
DirName string DirName string
} }
@ -48,7 +53,8 @@ func DirView(c *fiber.Ctx) error {
// Scraping // Scraping
Scrape := Dir{} Scrape := Dir{}
Scrape.Fullname = c.Params("user") + "/" + c.Params("repo") Scrape.Username = c.Params("user")
Scrape.Reponame = c.Params("repo")
Scrape.DirName = c.Params("+") Scrape.DirName = c.Params("+")
Scrape.Branch = c.Params("branch") Scrape.Branch = c.Params("branch")
@ -58,6 +64,11 @@ func DirView(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{
DomainGlob: "github.githubassets.com/*",
Delay: 5 * time.Second,
RandomDelay: 5 * time.Second,
})
sc.OnHTML("div#readme", func(e *colly.HTMLElement) { sc.OnHTML("div#readme", func(e *colly.HTMLElement) {
Scrape.Readme = e.ChildText("a[href='#readme']") Scrape.Readme = e.ChildText("a[href='#readme']")
}) })
@ -73,12 +84,23 @@ func DirView(c *fiber.Ctx) error {
} else { } else {
FileType = "file" FileType = "file"
} }
tstring := el.ChildAttr("relative-time", "datetime")
if tstring != "" {
tstring = strings.ReplaceAll(tstring, "T", "、")
tstring = strings.ReplaceAll(tstring, "Z", "")
tstring = strings.Split(tstring, "+")[0]
tstrings := strings.Split(tstring, "-")
tstring = tstrings[0] + "-" + tstrings[1] + "-" + tstrings[2]
}
if el.ChildText("div.flex-auto span.d-block a.js-navigation-open") != "" { if el.ChildText("div.flex-auto span.d-block a.js-navigation-open") != "" {
dirFilesArray = append(dirFilesArray, DirFiles{ dirFilesArray = append(dirFilesArray, DirFiles{
Name: el.ChildText("div.flex-auto span.d-block a.js-navigation-open"), Name: el.ChildText("div.flex-auto span.d-block a.js-navigation-open"),
Path: el.ChildText("div.flex-auto span.d-block a.js-navigation-open"), Path: el.ChildText("div.flex-auto span.d-block a.js-navigation-open"),
Commit: el.ChildText("div.flex-auto span.d-block a.Link--secondary"),
Date: tstring,
Type: FileType, Type: FileType,
Fullname: Scrape.Fullname, Username: Scrape.Username,
Reponame: Scrape.Reponame,
DirName: Scrape.DirName, DirName: Scrape.DirName,
Branch: Scrape.Branch, Branch: Scrape.Branch,
}) })

ファイルの表示

@ -78,6 +78,11 @@ 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{
DomainGlob: "github.githubassets.com/*",
Delay: 5 * time.Second,
RandomDelay: 5 * 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")
Scrape.Reponame = repoUrl Scrape.Reponame = repoUrl

ファイルの表示

@ -3,25 +3,31 @@
<main> <main>
{{ if .dir }} {{ range $key, $value := .dir}} {{ if .dir }} {{ range $key, $value := .dir}}
<div class="button-parent"> <div class="button-parent">
<a rel="noreferrer" href="https://github.com/{{.Fullname}}/tree/{{.Branch}}/{{.DirName}}" class="button">GitHubで確認</a> <a rel="noreferrer" href="https://github.com/{{.Username}}/{{.Reponame}}/tree/{{.Branch}}/{{.DirName}}" class="button">GitHubで確認</a>
<a href="/{{.Fullname}}/tree/{{.Branch}}/{{.Branch}}" class="button">{{.Fullname}}へ戻る</a> <a href="/{{.Username}}/{{.Reponame}}/tree/{{.Branch}}/{{.Branch}}" class="button">{{.Username}}/{{.Reponame}}へ戻る</a>
</div> </div>
<div class="user-profile"> <div class="user-profile">
<h1>{{.Fullname}} | {{.DirName}}</h1> <h1><a href="/{{.Username}}">{{.Username}}</a>/<a href="/{{.Username}}/{{.Reponame}}">{{.Reponame}}</a> | {{.DirName}}</h1>
</div> </div>
{{end}} {{ if .files}} {{end}} {{ if .files}}
<div class="user-readme"> <div class="user-readme">
<h3>ファイル</h3> <h3>ファイル</h3>
<div class="user-readme-text"> <table class="user-readme-text file-table">
<ul class="file-u-list"> <tbody>
{{ range $key, $value := .files}} {{ if eq .Type "dir" }} {{ range $key, $value := .files}}
<li class="file-list">📁 <a href="/{{.Fullname}}/tree/{{.Branch}}/{{.DirName}}/{{.Path}}" class="file-a">{{.Path}}</a></li> <tr class="file-u-list">
{{ else }} {{ if eq .Type "dir" }}
<li class="file-list">🗒️ <a href="/{{.Fullname}}/blob/{{.Branch}}/{{.DirName}}/{{.Path}}">{{.Path}}</a></li> <td class="file-list">📁 <a href="/{{.Username}}/{{.Reponame}}/tree/{{.Branch}}/{{.DirName}}/{{.Path}}" class="filesA">{{.Path}}</a></td>
{{ end }} {{ end }} {{ else }}
</ul> <td class="file-list">🗒️ <a href="/{{.Username}}/{{.Reponame}}/blob/{{.Branch}}/{{.DirName}}/{{.Path}}">{{.Path}}</a></td>
</div> {{ end }}
<td class="file-list">{{.Commit}}</td>
<td class="file-list" style="text-align: right;">{{.Date}}</td>
</tr>
{{ end }}
</tbody>
</table>
</div> </div>
{{ end }} {{ if .readme}} {{ end }} {{ if .readme}}
<div class="user-readme"> <div class="user-readme">