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

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

ファイルの表示

@ -5,6 +5,7 @@ import (
"net/http"
"os"
"strings"
"time"
"gitler.moe/suwako/gitlin/utils"
"github.com/gocolly/colly"
@ -13,7 +14,8 @@ import (
type Dir struct {
Readme string
Fullname string
Username string
Reponame string
DirName string
Branch string
}
@ -21,9 +23,12 @@ type Dir struct {
type DirFiles struct {
Name string
Path string
Commit string
Date string
Type string
Branch string
Fullname string
Username string
Reponame string
DirName string
}
@ -48,7 +53,8 @@ func DirView(c *fiber.Ctx) error {
// Scraping
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.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.Limit(&colly.LimitRule{
DomainGlob: "github.githubassets.com/*",
Delay: 5 * time.Second,
RandomDelay: 5 * time.Second,
})
sc.OnHTML("div#readme", func(e *colly.HTMLElement) {
Scrape.Readme = e.ChildText("a[href='#readme']")
})
@ -73,12 +84,23 @@ func DirView(c *fiber.Ctx) error {
} else {
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") != "" {
dirFilesArray = append(dirFilesArray, DirFiles{
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"),
Commit: el.ChildText("div.flex-auto span.d-block a.Link--secondary"),
Date: tstring,
Type: FileType,
Fullname: Scrape.Fullname,
Username: Scrape.Username,
Reponame: Scrape.Reponame,
DirName: Scrape.DirName,
Branch: Scrape.Branch,
})

ファイルの表示

@ -78,6 +78,11 @@ 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: 5 * time.Second,
RandomDelay: 5 * time.Second,
})
sc.OnHTML("div.Layout-sidebar", func(e *colly.HTMLElement) {
Scrape.Username = c.Params("user")
Scrape.Reponame = repoUrl

ファイルの表示

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