Add repo page

Signed-off-by: Odyssey <odyssey346@disroot.org>
このコミットが含まれているのは:
Odyssey 2022-11-30 15:08:16 +01:00
コミット a9105ac80b
6個のファイルの変更129行の追加2行の削除

10
main.go
ファイルの表示

@ -93,6 +93,7 @@ func main() {
app.Static("/logo.svg", "./public/assets/logo.svg")
app.Get("/explore", ratelimiter, pages.HandleExplore)
app.Get("/:user", ratelimiter, pages.HandleUser)
app.Get("/:user/:repo", ratelimiter, pages.HandleRepo)
app.Get("/avatar/:id", func(c *fiber.Ctx) error {
url := "https://avatars.githubusercontent.com/u/" + c.Params("id") + "?v=4"
if err := proxy.Do(c, url); err != nil {
@ -102,5 +103,14 @@ func main() {
c.Response().Header.Del(fiber.HeaderServer)
return nil
})
app.Get("/download/:user/:repo/:branch", ratelimiter, func(c *fiber.Ctx) error {
url := "https://github.com/" + c.Params("user") + "/" + c.Params("repo") + "/archive/" + c.Params("branch") + ".zip"
if err := proxy.Do(c, url); err != nil {
return err
}
// Remove Server header from response
c.Response().Header.Del(fiber.HeaderServer)
return nil
})
log.Fatal(app.Listen(":3000"))
}

ファイルの表示

@ -20,7 +20,7 @@ type Items struct {
func HandleExplore(c *fiber.Ctx) error {
// get trending repos
trendingRepos := utils.GetRequest("https://api.github.com/search/repositories?q=code&sort=stars&order=desc&per_page=25")
bruh2 := trendingRepos.Get("items").Array() // gjson.Result when I ask for an array. idiots, anyway so I have to do jank shit like this and I hate it. at least it works and is fast enough
bruh2 := trendingRepos.Get("tree").Array() // gjson.Result when I ask for an array. idiots, anyway so I have to do jank shit like this and I hate it. at least it works and is fast enough
var trendingReposArray []Items
for _, item := range bruh2 {
trendingReposArray = append(trendingReposArray, Items{

49
pages/repo.go ノーマルファイル
ファイルの表示

@ -0,0 +1,49 @@
package pages
import (
"codeberg.org/Odyssium/gothub/utils"
"github.com/gofiber/fiber/v2"
)
type Repo struct {
Fullname string
Description string
HtmlUrl string
Fork bool
Parent string
Stars int64
Forks int64
Watchers int64
Language string
License string
DefaultBranch string
}
type RepoFiles struct {
Name string
Path string
Type string
}
func HandleRepo(c *fiber.Ctx) error {
var repoArray []Repo
// get repo
repo := utils.GetRequest("https://api.github.com/repos/" + c.Params("user") + "/" + c.Params("repo"))
repoArray = append(repoArray, Repo{
Fullname: repo.Get("full_name").String(),
Description: repo.Get("description").String(),
HtmlUrl: repo.Get("html_url").String(),
Fork: repo.Get("fork").Bool(),
Stars: repo.Get("stargazers_count").Int(),
Forks: repo.Get("forks_count").Int(),
Watchers: repo.Get("watchers_count").Int(),
Language: repo.Get("language").String(),
License: repo.Get("license").Get("name").String(),
Parent: repo.Get("parent").Get("full_name").String(),
DefaultBranch: repo.Get("default_branch").String(),
})
return c.Render("repo", fiber.Map{
"repo": repoArray,
})
}

ファイルの表示

@ -150,6 +150,30 @@ a:hover {
margin-top: 0;
}
/* URI: /:user/:repo */
.downloadButton {
background-color: var(--background);
padding: 8px;
border-radius: 8px;
margin: 8px;
color: var(--text);
text-decoration: none;
text-align: center;
display: inline-block;
}
.downloadButton:hover {
background-color: var(--accent);
color: var(--text);
}
.buttonParent {
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
@media screen and (prefers-color-scheme: light) {
:root {
--text: #000;

ファイルの表示

@ -6,7 +6,7 @@
{{ if .repos}}
{{ range $key, $value := .repos}}
<div class="exploreIDontKnowWhatToNameThisDiv">
<a href="{{ .HtmlUrl }}">{{ .Fullname }}</a>
<a href="/{{.Fullname}}">{{ .Fullname }}</a>
<p>{{.Description}}</p>
{{ if .Language }}
{{ if .License }}

44
views/repo.html ノーマルファイル
ファイルの表示

@ -0,0 +1,44 @@
{{ template "header" .}}
<main>
{{ if .repo }}
{{ range $key, $value := .repo}}
<div class="buttonParent">
<a href="/download/{{.Fullname}}/{{.DefaultBranch}}" class="downloadButton">Download (zip)</a>
</div>
<div class="userProfile">
<h1>{{.Fullname}}</h1>
{{ if .Fork }}
<p>This repository is a fork of <a href="/{{.Parent}}">{{.Parent}}</a>.</p>
{{ end }}
{{ if .Description }}
<p>{{.Description}}</p>
{{ end }}
{{ if .Language}}
{{ if .License }}
<p>⭐ {{.Stars}} 🍴 {{.Forks}} 👀 {{.Watchers}} ⚖️ {{.License}} 🗒️ {{.Language}}</p>
{{ else }}
<p>⭐ {{.Stars}} 🍴 {{.Forks}} 👀 {{.Watchers}} ⚖️ No license 🗒️ {{.Language}}</p>
{{ end }}
{{ else }}
{{ end }}
</div>
{{end}}
<!-- {{ if .files}}
<div class="userReadme">
<h3>Files</h3>
<div class="userReadmeText">
<ul>
{{ range $key, $value := .files}}
<li><a href="/{{.Fullname}}/{{.Path}}">{{.Path}}</a></li>
{{ end }}
</ul>
</div>
</div>
{{ end }} -->
{{ else }}
<h2>Repository not found</h2>
<p>That repository doesn't exist.</p>
{{ end }}
</main>