specify branch using ldflag (closes #63)

This commit is contained in:
Arya Kiran
2023-04-28 22:38:04 +05:30
parent 93b5a7b08b
commit 18876e9105
12 changed files with 33 additions and 20 deletions
+1
View File
@@ -39,6 +39,7 @@ func HandleAbout(c *fiber.Ctx) error {
return c.Render("about", fiber.Map{
"title": "About this instance",
"branch": utils.Branch,
"privacyInformation": privacyInfoArray,
})
}
+1
View File
@@ -88,6 +88,7 @@ func DirView(c *fiber.Ctx) error {
dirArray = append(dirArray, Scrape)
return c.Render("dir", fiber.Map{
"title": "Directory " + c.Params("+") + " | " + c.Params("user") + "/" + c.Params("repo"),
"branch": utils.Branch,
"dir": dirArray,
"files": dirFilesArray,
"readme": string(readmeOutput),
+3 -2
View File
@@ -36,7 +36,8 @@ func HandleExplore(c *fiber.Ctx) error {
}
return c.Render("explore", fiber.Map{
"title": "Explore",
"repos": trendingReposArray,
"title": "Explore",
"branch": utils.Branch,
"repos": trendingReposArray,
})
}
+9 -8
View File
@@ -3,14 +3,14 @@ package pages
import (
"bufio"
"bytes"
"codeberg.org/gothub/gothub/utils"
"context"
"html/template"
htmlfmt "github.com/alecthomas/chroma/v2/formatters/html"
"github.com/alecthomas/chroma/v2/lexers"
"github.com/alecthomas/chroma/v2/styles"
"github.com/carlmjohnson/requests"
"github.com/gofiber/fiber/v2"
"html/template"
)
// FileView is the file view page
@@ -57,11 +57,12 @@ func FileView(c *fiber.Ctx) error {
writer.Flush()
cssw.Flush()
return c.Render("file", fiber.Map{
"title": c.Params("+") + " | " + c.Params("user") + "/" + c.Params("repo"),
"file": template.HTML(buf.String()),
"css": template.CSS(cssbuf.String()),
"fullname": c.Params("user") + "/" + c.Params("repo"),
"name": c.Params("+"),
"branch": c.Params("branch"),
"title": c.Params("+") + " | " + c.Params("user") + "/" + c.Params("repo"),
"branch": utils.Branch,
"file": template.HTML(buf.String()),
"css": template.CSS(cssbuf.String()),
"fullname": c.Params("user") + "/" + c.Params("repo"),
"name": c.Params("+"),
"fileBranch": c.Params("branch"),
})
}
+5 -3
View File
@@ -3,6 +3,7 @@ package pages
import (
"bufio"
"bytes"
"codeberg.org/gothub/gothub/utils"
"context"
htmlfmt "github.com/alecthomas/chroma/v2/formatters/html"
"github.com/alecthomas/chroma/v2/lexers"
@@ -131,8 +132,9 @@ func HandleGist(c *fiber.Ctx) error {
gistArray = append(gistArray, Scrape)
return c.Render("gist", fiber.Map{
"title": "Repository " + c.Params("user") + "/" + c.Params("gistID"),
"gist": gistArray,
"files": gistFilesArray,
"title": "Repository " + c.Params("user") + "/" + c.Params("gistID"),
"branch": utils.Branch,
"gist": gistArray,
"files": gistFilesArray,
})
}
+1
View File
@@ -11,6 +11,7 @@ import (
func HandleIndex(c *fiber.Ctx) error {
return c.Render("index", fiber.Map{
"host": c.Hostname(),
"branch": utils.Branch,
"version": utils.Version(),
"fiberversion": fiber.Version,
"goversion": runtime.Version(),
+1
View File
@@ -121,6 +121,7 @@ func HandleRepo(c *fiber.Ctx) error {
repoArray = append(repoArray, Scrape)
return c.Render("repo", fiber.Map{
"title": c.Params("user") + "/" + repoUrl + branchExists,
"branch": utils.Branch,
"repo": repoArray,
"files": repoFilesArray,
"readme": readmeOutput,
+3 -2
View File
@@ -181,7 +181,8 @@ func HandleUser(c *fiber.Ctx) error {
userArray = append(userArray, Scrape)
return c.Render("user", fiber.Map{
"title": c.Params("user"),
"user": userArray,
"title": c.Params("user"),
"branch": utils.Branch,
"user": userArray,
})
}
+5 -3
View File
@@ -47,8 +47,9 @@ func Serve(port string) {
}
_, link := regexp.MatchString(`\/.*\ `, err.Error())
err = ctx.Status(code).Render("error", fiber.Map{
"error": err,
"link": link,
"error": err,
"link": link,
"branch": utils.Branch,
})
if err != nil {
return ctx.Status(fiber.StatusInternalServerError).SendString("Internal Server Error")
@@ -73,7 +74,8 @@ func Serve(port string) {
Expiration: 5 * time.Minute,
LimitReached: func(c *fiber.Ctx) error {
return c.Status(429).Render("ratelimit_gt", fiber.Map{
"Title": "Rate limit exceeded",
"Title": "Rate limit exceeded",
"branch": utils.Branch,
})
},
})
+2
View File
@@ -4,6 +4,8 @@ import (
"runtime/debug"
)
var Branch = "Alpha"
// Version returns the git commit hash of the current build. Taken from https://git.vern.cc/pjals/bestofbot.
func Version() string {
if info, ok := debug.ReadBuildInfo(); ok {
+1 -1
View File
@@ -11,7 +11,7 @@
}
</style>
<div class="download-parent">
<a href="/{{.fullname}}/tree/{{.branch}}" class="button"
<a href="/{{.fullname}}/tree/{{.fileBranch}}" class="button"
>Back to {{.fullname}}</a
>
</div>
+1 -1
View File
@@ -20,7 +20,7 @@
height="30"
width="30"
alt=""
><b class="navbar-slogan">GotHub (alpha)</b></a
><b class="navbar-slogan">GotHub ({{.branch}})</b></a
>
<div class="navbar-links">
<a href="/explore">Explore</a>