Merge pull request 'Merge dev into master' (#28) from dev into master

Reviewed-on: https://codeberg.org/gothub/gothub/pulls/28
Reviewed-by: Midou36O <midou36o@noreply.codeberg.org>
This commit is contained in:
Odyssium
2023-01-01 00:14:55 +00:00
9 changed files with 134 additions and 23 deletions
+2 -2
View File
@@ -7,9 +7,9 @@ RUN apk --no-cache add git
RUN git clone https://codeberg.org/gothub/gothub .
RUN go mod download
RUN GOOS=linux GOARCH=$TARGETARCH go build -ldflags "-X codeberg.org/gothub/gothub/pages.Version=$(git rev-parse --short HEAD)" -o /src/gothub
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 .
+38 -4
View File
@@ -1,8 +1,42 @@
# gothub
# GotHub
Alternative front-end for GitHub written with Go.
Alternative front-end for GitHub written with Go. (WIP)
[Matrix](https://matrix.to/#/%23gothub%3Atrygve.me?via=projectsegfau.lt&via=vern.cc&via=matrix.org&via=trygve.me)
## [Matrix](https://matrix.to/#/%23gothub%3Atrygve.me?via=projectsegfau.lt&via=vern.cc&via=matrix.org&via=trygve.me)
## Features
- Lightweight - for both you and the instance host
- No JavaScript - pure HTML and CSS goodness
- No requests made to Micro$oft - they won't even know you made a request!
- Open source - for peer review & trustworthiness
- Save bandwidth - no JavaScript/tracking bloat loaded!
## Instances
The instances list is in the [wiki](https://codeberg.org/gothub/gothub/wiki/Instances).
## Setup
### Docker
We recommend Docker as it is easy to update GotHub that way and it is easy to setup.
[Packages page](https://codeberg.org/gothub/-/packages/container/gothub/latest)
```
docker run -d -p 3000:3000 --name gothub codeberg.org/gothub/gothub
```
If you are using Portainer or Podman, you know how to create the GotHub container.
### Manual
You will need an installation of Go 1.19+ installed on your system.
```bash
git clone https://codeberg.org/gothub/gothub.git
cd gothub
go build -o gothub
./gothub serve
```
If you don't want to use port 3000 for GotHub, set the GOTHUB_PORT environment variable to the port you want to use.
### This project is still in development. ⚠️
## 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.
+3 -1
View File
@@ -3,17 +3,20 @@ module codeberg.org/gothub/gothub
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/template v1.7.3
github.com/gomarkdown/markdown v0.0.0-20221013030248-663e2500819c
github.com/microcosm-cc/bluemonday v1.0.21
github.com/spf13/cobra v1.6.1
github.com/tidwall/gjson v1.14.4
)
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/gorilla/css v1.0.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/klauspost/compress v1.15.12 // indirect
@@ -21,7 +24,6 @@ require (
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/rivo/uniseg v0.4.3 // indirect
github.com/spf13/cobra v1.6.1 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
+7
View File
@@ -54,6 +54,10 @@ github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3
github.com/Joker/hpp v1.0.0/go.mod h1:8x5n+M1Hp5hC0g8okX3sR3vFQwynaX/UgSOM9MeBKzY=
github.com/Joker/jade v1.1.3/go.mod h1:T+2WLyt7VH6Lp0TRxQrUYEs64nRc83wkMQrfeIQKduM=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/alecthomas/assert/v2 v2.2.0 h1:f6L/b7KE2bfA+9O4FL3CM/xJccDEwPVYd5fALBiuwvw=
github.com/alecthomas/chroma/v2 v2.4.0 h1:Loe2ZjT5x3q1bcWwemqyqEi8p11/IV/ncFCeLYDpWC4=
github.com/alecthomas/chroma/v2 v2.4.0/go.mod h1:6kHzqF5O6FUSJzBXW7fXELjb+e+7OXW4UpoPqMO7IBQ=
github.com/alecthomas/repr v0.1.0 h1:ENn2e1+J3k09gyj2shc0dHr/yjaWSHRlrJ4DPMevDqE=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
@@ -104,6 +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/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=
@@ -243,6 +249,7 @@ github.com/hashicorp/memberlist v0.2.2/go.mod h1:MS2lj3INKhZjWNqd3N0m3J+Jxf3DAOn
github.com/hashicorp/memberlist v0.3.0/go.mod h1:MS2lj3INKhZjWNqd3N0m3J+Jxf3DAOnAH9VT3Sh9MUE=
github.com/hashicorp/serf v0.9.5/go.mod h1:UWDWwZeL5cuWDJdl0C6wrvrUwEqtQ4ZKBKKENpqIUyk=
github.com/hashicorp/serf v0.9.6/go.mod h1:TXZNMjZQijwlDvp+r0b63xZ45H7JmCmgg4gpTwn9UV4=
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
+16 -2
View File
@@ -1,8 +1,22 @@
package pages
import "github.com/gofiber/fiber/v2"
import (
"runtime/debug"
var Version = "unknown"
"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{
+19 -5
View File
@@ -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 {
@@ -187,19 +190,30 @@ a:hover {
}
/* URI: /file/:user/:repo/:file */
.filePre {
background-color: var(--background-darker);
color: var(--text);
.userReadme pre {
padding: 8px;
border-radius: 8px;
white-space: pre-wrap;
/*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 {
@@ -251,4 +265,4 @@ a:hover {
margin-bottom: 8px;
margin-right: 0;
}
}
}
+40 -1
View File
@@ -1,6 +1,8 @@
package serve
import (
"bufio"
"bytes"
"context"
"html/template"
"log"
@@ -9,6 +11,11 @@ import (
"codeberg.org/gothub/gothub/pages"
"github.com/carlmjohnson/requests"
htmlfmt "github.com/alecthomas/chroma/v2/formatters/html"
"github.com/alecthomas/chroma/v2/lexers"
"github.com/alecthomas/chroma/v2/styles"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cache"
"github.com/gofiber/fiber/v2/middleware/compress"
@@ -105,8 +112,40 @@ func Serve() {
"error": err,
})
}
lexer := lexers.Match(c.Params("file"))
if lexer == nil {
lexer = lexers.Fallback
}
formatter := htmlfmt.New(
htmlfmt.WithClasses(true),
htmlfmt.WithLineNumbers(true),
htmlfmt.PreventSurroundingPre(false),
)
buf := bytes.Buffer{}
writer := bufio.NewWriter(&buf)
style := styles.Get("native")
tokens, err := lexer.Tokenise(nil, file)
if err != nil {
return c.Status(500).Render("error", fiber.Map{
"error": err,
})
}
formatter.Format(writer, style, tokens)
cssbuf := bytes.Buffer{}
cssw := bufio.NewWriter(&cssbuf)
formatter.WriteCSS(cssw, style)
writer.Flush()
cssw.Flush()
return c.Render("file", fiber.Map{
"file": file,
"file": template.HTML(buf.String()),
"css": template.CSS(cssbuf.String()),
"fullname": c.Params("user") + "/" + c.Params("repo"),
"name": c.Params("file"),
"branch": c.Params("branch"),
+8 -7
View File
@@ -2,16 +2,17 @@
<main>
{{ if .file }}
<style>{{ .css }}</style>
<div class="downloadParent">
<a href="/{{.fullname}}" class="downloadButton">Back to {{.fullname}}</a>
<a href="/{{.fullname}}" class="button">Back to {{.fullname}}</a>
</div>
<div class="userReadme">
<h3>{{.name}}</h3>
<pre class="filePre">{{ .file}}</pre>
</div>
<div class="downloadParent">
<a href="/raw/{{.fullname}}/{{.branch}}/{{.name}}" class="downloadButton">Download</a>
<div class="userContainer">
<h3>{{.name}}</h3>
<a href="/raw/{{.fullname}}/{{.branch}}/{{.name}}" class="button secondary">Raw</a>
</div>
{{ .file}}
</div>
{{end}}
</main>
</main>
+1 -1
View File
@@ -9,7 +9,7 @@
<div class="userProfile">
<img src="{{ .AvatarUrl }}" alt="{{.Login}}'s avatar" class="avatar" width="150" height="150">
{{ if .Name }}
<h1>{{.Name}}</h1>
<h1 class="user-profile-h1">{{.Name}}</h1>
{{ end }}
<h2>{{.Login}}</h2>
{{ if eq .Type "User" }}