Files
Arya K 30a68263e7 Merge dev into master (#107)
Co-authored-by: Odyssium <hi@odyssey346.dev>
Co-authored-by: Midou36O <facemioo4@gmail.com>
Co-authored-by: Arya Kiran <arya@projectsegfau.lt>
Co-authored-by: Odyssium <odyssium@noreply.codeberg.org>
Co-authored-by: medanisjbara <medanisjbara@proton.me>
Co-authored-by: Midou36O <midou36o@noreply.codeberg.org>
Co-authored-by: No-Logs.com <no-logs@noreply.codeberg.org>
Reviewed-on: https://codeberg.org/gothub/gothub/pulls/107
2023-05-08 10:24:08 +00:00

44 lines
1.3 KiB
Go

package pages
import (
"github.com/gofiber/fiber/v2"
"codeberg.org/gothub/gothub/utils"
)
type Items struct {
Fullname string
Description string
HtmlUrl string
Stars int64
Forks int64
Watchers int64
Language string
License string
}
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")
gjsonArray := 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
var trendingReposArray []Items
for _, item := range gjsonArray {
trendingReposArray = append(trendingReposArray, Items{
Fullname: item.Get("full_name").String(),
Description: item.Get("description").String(),
HtmlUrl: item.Get("html_url").String(),
Stars: item.Get("stargazers_count").Int(),
Forks: item.Get("forks_count").Int(),
Watchers: item.Get("watchers_count").Int(),
Language: item.Get("language").String(),
License: item.Get("license").Get("name").String(),
})
}
return c.Render("explore", fiber.Map{
"title": "Explore",
"branch": utils.Branch,
"repos": trendingReposArray,
})
}