diff --git a/Dockerfile b/Dockerfile index 841f7b9..95f9900 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,13 +9,14 @@ 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 . 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 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 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/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/index.go b/pages/index.go index 608600d..5ed4f0e 100644 --- a/pages/index.go +++ b/pages/index.go @@ -1,26 +1,17 @@ package pages import ( - "runtime/debug" + "runtime" + "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, + "host": c.Hostname(), + "version": utils.Version(), + "fiberversion": fiber.Version, + "goversion": runtime.Version(), }) } 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/public/css/global.css b/public/css/global.css index 8f18658..ef3249b 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 { @@ -188,18 +191,29 @@ a:hover { /* URI: /file/:user/:repo/:file */ .userReadme pre { - background-color: var(--background-darker); padding: 8px; border-radius: 8px; /*white-space: pre-wrap;*/ 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/serve/serve.go b/serve/serve.go index 2c3d61a..e876d21 100644 --- a/serve/serve.go +++ b/serve/serve.go @@ -7,9 +7,11 @@ import ( "html/template" "log" "os" + "runtime" "time" "codeberg.org/gothub/gothub/pages" + "codeberg.org/gothub/gothub/utils" "github.com/carlmjohnson/requests" htmlfmt "github.com/alecthomas/chroma/v2/formatters/html" @@ -169,6 +171,17 @@ 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 { + return c.JSON(fiber.Map{ + "version": utils.Version(), + "fiberversion": fiber.Version, + "goversion": runtime.Version(), + }) + }) + val, ok := os.LookupEnv("GOTHUB_PORT") if !ok { val = "3000" 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" +} 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 @@
Just replace github.com with {{.host}}!
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.unknown
{{ else }}
GotHub version: {{ .version}}
{{ end }}
+