From 286fe9c7a0c5494a1b38ac135c4a7686c3a82c50 Mon Sep 17 00:00:00 2001 From: Odyssey Date: Tue, 27 Dec 2022 15:19:26 +0100 Subject: [PATCH 01/10] Add a legal notice (closes #23) Signed-off-by: Odyssey --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index cf9791e..b5262d0 100644 --- a/README.md +++ b/README.md @@ -33,3 +33,10 @@ go build -o gothub ``` If you don't want to use port 3000 for GotHub, set the GOTHUB_PORT environment variable to the port you want to use. + + +## DMCA/Legal notice + +All content shown on a GotHub instance is from GitHub. Any issues with content shown on a GotHub instance needs to be reported to GitHub, not the instance host's internet or domain provider. + +GitHub is a registered trademark of GitHub, Inc. GotHub is not affiliated with GitHub, Inc. \ No newline at end of file From de9ab67e8cf9f01c5aa10a9b17c6ca25f97f3e87 Mon Sep 17 00:00:00 2001 From: Odyssey Date: Tue, 27 Dec 2022 15:40:12 +0100 Subject: [PATCH 02/10] Add raw button to file view Signed-off-by: Odyssey --- public/css/global.css | 15 +++++++++++++++ views/file.html | 8 ++++---- views/user.html | 2 +- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/public/css/global.css b/public/css/global.css index 8f18658..9dc1c10 100644 --- a/public/css/global.css +++ b/public/css/global.css @@ -9,6 +9,7 @@ :root { --text: #fff; --background: #252525; + --secondary-background: #353535; --background-darker: #151515; --accent: #00b7c3; } @@ -117,6 +118,8 @@ a:hover { .userProfile h1 { color: #00b7c3; margin: 4px; + word-wrap: nowrap; + text-overflow: ellipsis; } .userProfile h2 { @@ -195,11 +198,23 @@ a:hover { overflow-x: auto; } +.userContainer { + display: flex; + flex-direction: row; + justify-content: space-between; + align-items: center; +} + + +.secondary { + background-color: var(--secondary-background); +} @media screen and (prefers-color-scheme: light) { :root { --text: #000; --background: #f1f1f1; + --secondary-background: #e1e1e1; --background-darker: #fff; } body { diff --git a/views/file.html b/views/file.html index d949669..7f50c4d 100644 --- a/views/file.html +++ b/views/file.html @@ -8,11 +8,11 @@
-

{{.name}}

+
+

{{.name}}

+ Raw +
{{ .file}}
-
- Download -
{{end}} diff --git a/views/user.html b/views/user.html index a071c11..127751f 100644 --- a/views/user.html +++ b/views/user.html @@ -9,7 +9,7 @@
{{.Login}}'s avatar {{ if .Name }} -

{{.Name}}

+

{{.Name}}

{{ end }}

{{.Login}}

{{ if eq .Type "User" }} From 40dcdcf68cbd59f1f15714023495856d56bd70fd Mon Sep 17 00:00:00 2001 From: Odyssey Date: Sun, 1 Jan 2023 00:27:10 +0100 Subject: [PATCH 03/10] switch to alpine for docker image Signed-off-by: Odyssey --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 841f7b9..399cd0c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,7 +9,7 @@ RUN git clone https://codeberg.org/gothub/gothub . RUN go mod download RUN GOOS=linux GOARCH=$TARGETARCH go build -o /src/gothub -FROM scratch as bin +FROM alpine:3.16 as bin WORKDIR /app COPY --from=build /src/gothub . From 7eb43d9c97aab20c17b9e37e728ba0f85007c777 Mon Sep 17 00:00:00 2001 From: Odyssey Date: Sun, 1 Jan 2023 01:10:16 +0100 Subject: [PATCH 04/10] Syntax Highlighting CSS fix. Signed-off-by: Odyssey --- public/css/global.css | 1 - 1 file changed, 1 deletion(-) diff --git a/public/css/global.css b/public/css/global.css index 9dc1c10..ef3249b 100644 --- a/public/css/global.css +++ b/public/css/global.css @@ -191,7 +191,6 @@ a:hover { /* URI: /file/:user/:repo/:file */ .userReadme pre { - background-color: var(--background-darker); padding: 8px; border-radius: 8px; /*white-space: pre-wrap;*/ From de088ef1072de7c988ef79959d3416f38baf0229 Mon Sep 17 00:00:00 2001 From: Odyssey Date: Thu, 5 Jan 2023 17:42:36 +0100 Subject: [PATCH 05/10] Update dependencies and add fiber/go version Signed-off-by: Odyssey --- go.mod | 12 ++++++------ go.sum | 22 ++++++++++++---------- pages/index.go | 7 +++++-- views/index.html | 4 +++- 4 files changed, 26 insertions(+), 19 deletions(-) diff --git a/go.mod b/go.mod index b4e2e54..9729f25 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.19 require ( github.com/alecthomas/chroma/v2 v2.4.0 github.com/carlmjohnson/requests v0.22.3 - github.com/gofiber/fiber/v2 v2.40.1 + github.com/gofiber/fiber/v2 v2.41.0 github.com/gofiber/template v1.7.3 github.com/gomarkdown/markdown v0.0.0-20221013030248-663e2500819c github.com/microcosm-cc/bluemonday v1.0.21 @@ -16,12 +16,12 @@ require ( require ( github.com/andybalholm/brotli v1.0.4 // indirect github.com/aymerick/douceur v0.2.0 // indirect - github.com/dlclark/regexp2 v1.4.0 // indirect + github.com/dlclark/regexp2 v1.7.0 // indirect github.com/gorilla/css v1.0.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect - github.com/klauspost/compress v1.15.12 // indirect + github.com/klauspost/compress v1.15.14 // indirect github.com/mattn/go-colorable v0.1.13 // indirect - github.com/mattn/go-isatty v0.0.16 // indirect + github.com/mattn/go-isatty v0.0.17 // indirect github.com/mattn/go-runewidth v0.0.14 // indirect github.com/rivo/uniseg v0.4.3 // indirect github.com/spf13/pflag v1.0.5 // indirect @@ -30,6 +30,6 @@ require ( github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/fasthttp v1.43.0 // indirect github.com/valyala/tcplisten v1.0.0 // indirect - golang.org/x/net v0.2.0 // indirect - golang.org/x/sys v0.2.0 // indirect + golang.org/x/net v0.5.0 // indirect + golang.org/x/sys v0.4.0 // indirect ) diff --git a/go.sum b/go.sum index 22c5908..8ba98c8 100644 --- a/go.sum +++ b/go.sum @@ -108,8 +108,8 @@ github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46t github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/dlclark/regexp2 v1.4.0 h1:F1rxgk7p4uKjwIQxBs9oAXe5CqrXlCduYEJvrF4u93E= -github.com/dlclark/regexp2 v1.4.0/go.mod h1:2pZnwuY/m+8K6iRw6wQdMtk+rH5tNGR1i55kozfMjCc= +github.com/dlclark/regexp2 v1.7.0 h1:7lJfhqlPssTb1WQx4yvTHN0uElPEv52sbaECrAQxjAo= +github.com/dlclark/regexp2 v1.7.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8= github.com/eknkc/amber v0.0.0-20171010120322-cdade1c07385/go.mod h1:0vRUJqYpeSZifjYj7uP3BG/gKcuzL9xWVV/Y+cK33KM= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= @@ -137,8 +137,9 @@ github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9 github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= -github.com/gofiber/fiber/v2 v2.40.1 h1:pc7n9VVpGIqNsvg9IPLQhyFEMJL8gCs1kneH5D1pIl4= github.com/gofiber/fiber/v2 v2.40.1/go.mod h1:Gko04sLksnHbzLSRBFWPFdzM9Ws9pRxvvIaohJK1dsk= +github.com/gofiber/fiber/v2 v2.41.0 h1:YhNoUS/OTjEz+/WLYuQ01xI7RXgKEFnGBKMagAu5f0M= +github.com/gofiber/fiber/v2 v2.41.0/go.mod h1:RdebcCuCRFp4W6hr3968/XxwJVg0K+jr9/Ae0PFzZ0Q= github.com/gofiber/template v1.7.3 h1:ddWRgCB7kDdsgH7Qakwmlj6qM3kjggaT0aIhxLGatD0= github.com/gofiber/template v1.7.3/go.mod h1:MI/DIYL6czowb8KLkkNAojCifLnAVQcN3KGEUDvlFtU= github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ= @@ -267,8 +268,8 @@ github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7V github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/klauspost/compress v1.15.9/go.mod h1:PhcZ0MbTNciWF3rruxRgKxI5NkcHHrHUDtV4Yw2GlzU= -github.com/klauspost/compress v1.15.12 h1:YClS/PImqYbn+UILDnqxQCZ3RehC9N318SU3kElDUEM= -github.com/klauspost/compress v1.15.12/go.mod h1:QPwzmACJjUTFsnSHH934V6woptycfrDDJnH7hvFVbGM= +github.com/klauspost/compress v1.15.14 h1:i7WCKDToww0wA+9qrUZ1xOjp218vfFo3nTU6UHp+gOc= +github.com/klauspost/compress v1.15.14/go.mod h1:QPwzmACJjUTFsnSHH934V6woptycfrDDJnH7hvFVbGM= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg= github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc= @@ -292,8 +293,9 @@ github.com/mattn/go-isatty v0.0.10/go.mod h1:qgIWMr58cqv1PHHyhnkY9lrL7etaEgOFcME github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= -github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= +github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPng= +github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU= github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/mattn/go-slim v0.0.0-20200618151855-bde33eecb5ee/go.mod h1:ma9TUJeni8LGZMJvOwbAv/FOwiwqIMQN570LnpqCBSM= @@ -497,8 +499,8 @@ golang.org/x/net v0.0.0-20210813160813-60bc85c4be6d/go.mod h1:9nx3DQGgdP8bBQD5qx golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/net v0.0.0-20220906165146-f3363e06e74c/go.mod h1:YDH+HFinaLZZlnHAfSS6ZXJJ9M9t4Dl22yv3iI2vPwk= -golang.org/x/net v0.2.0 h1:sZfSu1wtKLGlWI4ZZayP0ck9Y73K1ynO6gqzTdBVdPU= -golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY= +golang.org/x/net v0.5.0 h1:GyT4nK/YDHSqa1c4753ouYCDajOYKTja9Xb/OHtgvSw= +golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -595,8 +597,8 @@ golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20211205182925-97ca703d548d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220728004956-3c1f35247d10/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.2.0 h1:ljd4t30dBnAvMZaQCevtY0xLLD0A+bRZXbgLMLU1F/A= -golang.org/x/sys v0.2.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18= +golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/pages/index.go b/pages/index.go index 608600d..430192a 100644 --- a/pages/index.go +++ b/pages/index.go @@ -1,6 +1,7 @@ package pages import ( + "runtime" "runtime/debug" "github.com/gofiber/fiber/v2" @@ -20,7 +21,9 @@ var Version = func() string { func HandleIndex(c *fiber.Ctx) error { return c.Render("index", fiber.Map{ - "host": c.Hostname(), - "version": Version, + "host": c.Hostname(), + "version": Version, + "fiberversion": fiber.Version, + "goversion": runtime.Version(), }) } diff --git a/views/index.html b/views/index.html index c1ea4f4..c7095fe 100644 --- a/views/index.html +++ b/views/index.html @@ -20,10 +20,12 @@ This project does not let you clone GitHub repositories. I would recommend using a VPN if you have to clone a GitHub repository and want to keep yourself private from them instead.

Credits

Midou36O - desigining the GotHub logo -

+

Info

{{ if eq .version "unknown"}} GotHub version: unknown {{ else }} GotHub version: {{ .version}} {{ end }} +
+Fiber version: {{ .fiberversion}}, running on {{ .goversion}} \ No newline at end of file From 02325162a8d07dfd0cc7934ef505447d4fa6484a Mon Sep 17 00:00:00 2001 From: Odyssey Date: Thu, 5 Jan 2023 17:45:54 +0100 Subject: [PATCH 06/10] Add extra legal notice (fixes #23) Signed-off-by: Odyssey --- views/index.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/views/index.html b/views/index.html index c7095fe..e6fe2c6 100644 --- a/views/index.html +++ b/views/index.html @@ -15,7 +15,7 @@

Usage

Just replace github.com with {{.host}}!

DMCA/Copyright Notice

-

All content shown on this site are from GitHub. Any issues with content shown on this site needs to be reported to GitHub, not the instance host's internet or domain provider.

+

All content shown on this site are from GitHub. Any issues with content shown on this site needs to be reported to GitHub, not the instance host's internet or domain provider. GitHub is a registered trademark of GitHub, Inc. GotHub is not affiliated with GitHub, Inc.

This project was made as a "spiritual successor" to Riverside Rocks' 1337git which is, unfortunately, hosted on GitHub. Kinda ironic.

This project does not let you clone GitHub repositories. I would recommend using a VPN if you have to clone a GitHub repository and want to keep yourself private from them instead.

Credits

From 30014eadb06cd9948501a0e64ffbd4ab7cef9bbd Mon Sep 17 00:00:00 2001 From: Odyssey Date: Thu, 5 Jan 2023 20:35:31 +0100 Subject: [PATCH 07/10] Add version API Signed-off-by: Odyssey --- serve/serve.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/serve/serve.go b/serve/serve.go index 2c3d61a..0cea417 100644 --- a/serve/serve.go +++ b/serve/serve.go @@ -7,6 +7,8 @@ import ( "html/template" "log" "os" + "runtime" + "runtime/debug" "time" "codeberg.org/gothub/gothub/pages" @@ -169,6 +171,28 @@ func Serve() { c.Response().Header.Del(fiber.HeaderServer) return nil }) + + api := app.Group("/api") + v1 := api.Group("/v1") + v1.Get("/version", func(c *fiber.Ctx) error { + // taken from https://git.vern.cc/pjals/bestofbot. + var Version = func() string { + if info, ok := debug.ReadBuildInfo(); ok { + for _, setting := range info.Settings { + if setting.Key == "vcs.revision" { + return setting.Value[:8] + } + } + } + return "unknown" + }() + return c.JSON(fiber.Map{ + "version": Version, + "fiberversion": fiber.Version, + "goversion": runtime.Version(), + }) + }) + val, ok := os.LookupEnv("GOTHUB_PORT") if !ok { val = "3000" From 8f95e44fab58ea6fc7b344eb44de9f5a47ff194d Mon Sep 17 00:00:00 2001 From: Odyssey Date: Thu, 5 Jan 2023 20:41:47 +0100 Subject: [PATCH 08/10] Add Docker environment variable (closes #15) Signed-off-by: Odyssey --- Dockerfile | 1 + 1 file changed, 1 insertion(+) diff --git a/Dockerfile b/Dockerfile index 399cd0c..95f9900 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,6 +16,7 @@ COPY --from=build /src/gothub . COPY --from=build /src/views ./views COPY --from=build /src/public ./public +ENV DOCKER true EXPOSE 3000 CMD ["/app/gothub", "serve"] \ No newline at end of file From a4a4e156739959f4cc9225eac19e43f961a9a8bc Mon Sep 17 00:00:00 2001 From: Odyssey Date: Thu, 5 Jan 2023 20:46:49 +0100 Subject: [PATCH 09/10] Make version a utility function Signed-off-by: Odyssey --- pages/index.go | 16 ++-------------- serve/serve.go | 15 ++------------- utils/version.go | 17 +++++++++++++++++ 3 files changed, 21 insertions(+), 27 deletions(-) create mode 100644 utils/version.go diff --git a/pages/index.go b/pages/index.go index 430192a..5ed4f0e 100644 --- a/pages/index.go +++ b/pages/index.go @@ -2,27 +2,15 @@ package pages import ( "runtime" - "runtime/debug" + "codeberg.org/gothub/gothub/utils" "github.com/gofiber/fiber/v2" ) -// taken from https://git.vern.cc/pjals/bestofbot. -var Version = func() string { - if info, ok := debug.ReadBuildInfo(); ok { - for _, setting := range info.Settings { - if setting.Key == "vcs.revision" { - return setting.Value[:8] - } - } - } - return "unknown" -}() - func HandleIndex(c *fiber.Ctx) error { return c.Render("index", fiber.Map{ "host": c.Hostname(), - "version": Version, + "version": utils.Version(), "fiberversion": fiber.Version, "goversion": runtime.Version(), }) diff --git a/serve/serve.go b/serve/serve.go index 0cea417..e876d21 100644 --- a/serve/serve.go +++ b/serve/serve.go @@ -8,10 +8,10 @@ import ( "log" "os" "runtime" - "runtime/debug" "time" "codeberg.org/gothub/gothub/pages" + "codeberg.org/gothub/gothub/utils" "github.com/carlmjohnson/requests" htmlfmt "github.com/alecthomas/chroma/v2/formatters/html" @@ -175,19 +175,8 @@ func Serve() { api := app.Group("/api") v1 := api.Group("/v1") v1.Get("/version", func(c *fiber.Ctx) error { - // taken from https://git.vern.cc/pjals/bestofbot. - var Version = func() string { - if info, ok := debug.ReadBuildInfo(); ok { - for _, setting := range info.Settings { - if setting.Key == "vcs.revision" { - return setting.Value[:8] - } - } - } - return "unknown" - }() return c.JSON(fiber.Map{ - "version": Version, + "version": utils.Version(), "fiberversion": fiber.Version, "goversion": runtime.Version(), }) diff --git a/utils/version.go b/utils/version.go new file mode 100644 index 0000000..a45512a --- /dev/null +++ b/utils/version.go @@ -0,0 +1,17 @@ +package utils + +import ( + "runtime/debug" +) + +// 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 { + for _, setting := range info.Settings { + if setting.Key == "vcs.revision" { + return setting.Value[:8] + } + } + } + return "unknown, please build with Go 1.13+ or use Git" +} From a928d70b0e50cbd8bb319886583c2aad27c1af7a Mon Sep 17 00:00:00 2001 From: Odyssey Date: Thu, 5 Jan 2023 20:58:41 +0100 Subject: [PATCH 10/10] Add titles Signed-off-by: Odyssey --- pages/explore.go | 1 + pages/repo.go | 2 ++ pages/user.go | 3 ++- views/header.html | 4 ++++ 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/pages/explore.go b/pages/explore.go index d038b43..3c7dcf4 100644 --- a/pages/explore.go +++ b/pages/explore.go @@ -36,6 +36,7 @@ func HandleExplore(c *fiber.Ctx) error { } return c.Render("explore", fiber.Map{ + "title": "Explore", "repos": trendingReposArray, }) } diff --git a/pages/repo.go b/pages/repo.go index 9645200..8e7792c 100644 --- a/pages/repo.go +++ b/pages/repo.go @@ -39,6 +39,7 @@ func HandleRepo(c *fiber.Ctx) error { repo := utils.GetRequest("https://api.github.com/repos/" + c.Params("user") + "/" + c.Params("repo")) if repo.Get("message").String() == "Not Found" { return c.Status(404).Render("error", fiber.Map{ + "title": "Error", "error": "Repository " + c.Params("user") + "/" + c.Params("repo") + " not found", }) } @@ -85,6 +86,7 @@ func HandleRepo(c *fiber.Ctx) error { }) return c.Render("repo", fiber.Map{ + "title": "Repository " + c.Params("user") + "/" + c.Params("repo"), "repo": repoArray, "files": repoFilesArray, "readme": string(readmeOutput), diff --git a/pages/user.go b/pages/user.go index 108c5fd..a09070a 100644 --- a/pages/user.go +++ b/pages/user.go @@ -112,7 +112,8 @@ func HandleUser(c *fiber.Ctx) error { fmt.Println(userArray) return c.Render("user", fiber.Map{ - "user": userArray, + "Title": "User " + c.Params("user"), + "user": userArray, }) } } diff --git a/views/header.html b/views/header.html index 1b63662..bf876bd 100644 --- a/views/header.html +++ b/views/header.html @@ -1,7 +1,11 @@ + {{ if .title }} + {{ .title }} - GotHub + {{ else }} GotHub + {{ end }}