From 976a3b946a94a0f33911bf66a9eb2bb1c773de04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AB=8F=E8=A8=AA=E5=AD=90?= Date: Wed, 7 Jun 2023 11:23:35 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=95=E3=82=A9=E3=83=AB=E3=83=80=E8=A1=A8?= =?UTF-8?q?=E7=A4=BA=E3=82=92=E3=83=86=E3=83=BC=E3=83=96=E3=83=AB=E5=8C=96?= =?UTF-8?q?=E3=80=81=E5=8F=8A=E3=81=B3=E3=82=B3=E3=83=9F=E3=83=A1=E3=81=A8?= =?UTF-8?q?=E6=97=A5=E6=99=82=E3=82=92=E3=81=8D=E3=81=A3=E3=81=A8=E8=A1=A8?= =?UTF-8?q?=E7=A4=BA=E3=81=99=E3=82=8B=E6=A7=98=E3=81=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/dirview.go | 30 ++++++++++++++++++++++++++---- pages/repo.go | 5 +++++ views/dir.html | 30 ++++++++++++++++++------------ 3 files changed, 49 insertions(+), 16 deletions(-) diff --git a/pages/dirview.go b/pages/dirview.go index b2fa5a4..da39ff7 100644 --- a/pages/dirview.go +++ b/pages/dirview.go @@ -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, }) diff --git a/pages/repo.go b/pages/repo.go index c519122..9b549d1 100644 --- a/pages/repo.go +++ b/pages/repo.go @@ -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 diff --git a/views/dir.html b/views/dir.html index d384924..65d88b6 100644 --- a/views/dir.html +++ b/views/dir.html @@ -3,25 +3,31 @@
{{ if .dir }} {{ range $key, $value := .dir}} {{end}} {{ if .files}}

ファイル

-
-
    - {{ range $key, $value := .files}} {{ if eq .Type "dir" }} -
  • 📁 {{.Path}}
  • - {{ else }} -
  • 🗒️ {{.Path}}
  • - {{ end }} {{ end }} -
-
+ + + {{ range $key, $value := .files}} + + {{ if eq .Type "dir" }} + + {{ else }} + + {{ end }} + + + + {{ end }} + +
📁 {{.Path}}🗒️ {{.Path}}{{.Commit}}{{.Date}}
{{ end }} {{ if .readme}}