aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Spek <p.spek@tyil.nl>2025-12-10 10:12:20 +0100
committerPatrick Spek <p.spek@tyil.nl>2025-12-10 10:12:20 +0100
commitba18e1d4e81d56ee03de4c9f3ca266e750f1e80b (patch)
treebb11160977ad1eafcb651a90a687282ab2eda4f7
parent5f0845339dafd5a2ed650e84f6a5b46f3c4629f5 (diff)
downloaddashlab-ba18e1d4e81d56ee03de4c9f3ca266e750f1e80b.tar.gz
dashlab-ba18e1d4e81d56ee03de4c9f3ca266e750f1e80b.tar.bz2
Expose README.md on /about
-rw-r--r--Containerfile10
-rw-r--r--config/func.go1
-rw-r--r--go.mod2
-rw-r--r--go.sum2
-rw-r--r--handlers/about.go90
-rw-r--r--main.go1
-rw-r--r--templates/about.gotpl19
-rw-r--r--templates/base.gotpl2
8 files changed, 121 insertions, 6 deletions
diff --git a/Containerfile b/Containerfile
index 8aca1ac..6c2db91 100644
--- a/Containerfile
+++ b/Containerfile
@@ -13,9 +13,11 @@ RUN go build -o /opt/dashlab/dashlab *.go
FROM alpine:latest
-ENV DASHLAB_CONFIG=/etc/dashlab.yaml
+ENV DASHLAB_CONFIG=/opt/dashlab/config.yaml
-COPY --from=build /src/dashlab/icon /opt/dashlab/icon
-COPY --from=build /opt/dashlab/dashlab /opt/dashlab/dashlab
+COPY --from=build /src/dashlab/README.md /opt/dashlab/README.md
+COPY --from=build /src/dashlab/config.yaml /opt/dashlab/config.yaml
+COPY --from=build /src/dashlab/icon /opt/dashlab/icon
+COPY --from=build /opt/dashlab/dashlab /opt/dashlab/dashlab
-CMD [ "/opt/dashlab" ]
+CMD [ "/opt/dashlab/dashlab" ]
diff --git a/config/func.go b/config/func.go
index 2ad574d..e30033d 100644
--- a/config/func.go
+++ b/config/func.go
@@ -25,7 +25,6 @@ import (
"strings"
"git.tyil.nl/go/env.git"
-
"go.yaml.in/yaml/v3"
)
diff --git a/go.mod b/go.mod
index 4680302..d6df351 100644
--- a/go.mod
+++ b/go.mod
@@ -6,3 +6,5 @@ require (
git.tyil.nl/go/env.git v0.0.0-20251209154418-f515a472af25
go.yaml.in/yaml/v3 v3.0.4
)
+
+require github.com/yuin/goldmark v1.7.13 // indirect
diff --git a/go.sum b/go.sum
index 407345c..7fd0c7a 100644
--- a/go.sum
+++ b/go.sum
@@ -1,5 +1,7 @@
git.tyil.nl/go/env.git v0.0.0-20251209154418-f515a472af25 h1:h+MUp0YI0EM2sjTYg/F+dho6z0DkfMJga1P1wgOWet0=
git.tyil.nl/go/env.git v0.0.0-20251209154418-f515a472af25/go.mod h1:AjmOD8BVTckCRSft6z1KBU3a7ZzvAhgZ1dNL7epl4x8=
+github.com/yuin/goldmark v1.7.13 h1:GPddIs617DnBLFFVJFgpo1aBfe/4xcvMc3SB5t/D0pA=
+github.com/yuin/goldmark v1.7.13/go.mod h1:ip/1k0VRfGynBgxOz0yCqHrbZXhcjxyuS66Brc7iBKg=
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
diff --git a/handlers/about.go b/handlers/about.go
new file mode 100644
index 0000000..9cd2ae8
--- /dev/null
+++ b/handlers/about.go
@@ -0,0 +1,90 @@
+// Copyright (C) 2025 Patrick "tyil" Spek <p.spek@tyil.nl>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as
+// published by the Free Software Foundation, either version 3 of the
+// License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+package handlers
+
+import (
+ "bytes"
+ "html/template"
+ "io/ioutil"
+ "log/slog"
+ "net/http"
+
+ "dashlab/config"
+ "dashlab/license"
+
+ "github.com/yuin/goldmark"
+)
+
+func About(res http.ResponseWriter, req *http.Request) {
+ // Get templates
+ tpl, err := template.ParseFiles(
+ "templates/base.gotpl",
+ "templates/about.gotpl",
+ )
+ if err != nil {
+ slog.Error(err.Error())
+
+ res.WriteHeader(http.StatusInternalServerError)
+ res.Write([]byte(err.Error()))
+
+ return
+ }
+
+ // Parse the README.md
+ var readme bytes.Buffer
+
+ data, err := ioutil.ReadFile("./README.md")
+ if err != nil {
+ slog.Error(
+ "Could not read README file",
+ "path", "./README.md",
+ "error", err.Error(),
+ )
+
+ res.WriteHeader(http.StatusInternalServerError)
+ res.Write([]byte(err.Error()))
+
+ return
+ }
+
+ err = goldmark.Convert(data, &readme)
+ if err != nil {
+ slog.Error(
+ "Could not parse README file",
+ "path", "./README.md",
+ "error", err.Error(),
+ )
+
+ res.WriteHeader(http.StatusInternalServerError)
+ res.Write([]byte(err.Error()))
+
+ return
+ }
+
+ // Return rendered template
+ err = tpl.Execute(res, map[string]interface{}{
+ "Announcement": config.Get().Announcement,
+ "License": template.HTML(license.AGPL_3_header_html),
+ "Title": config.Get().Title,
+ "Body": template.HTML(readme.String()),
+ })
+ if err != nil {
+ slog.Error(err.Error())
+
+ res.WriteHeader(http.StatusInternalServerError)
+ res.Write([]byte(err.Error()))
+ }
+}
diff --git a/main.go b/main.go
index 2170d59..4ffed6e 100644
--- a/main.go
+++ b/main.go
@@ -51,6 +51,7 @@ func main() {
mux.Handle("GET /icon/", http.StripPrefix("/icon", http.FileServer(http.Dir("./icon"))))
mux.Handle("GET /style.css", middleware.thenFunc(handlers.Stylesheet))
mux.Handle("GET /whoami", middleware.thenFunc(handlers.WhoAmI))
+ mux.Handle("GET /about", middleware.thenFunc(handlers.About))
mux.Handle("GET /-/healthz", middleware.thenFunc(handlers.Health))
mux.Handle("GET /", middleware.thenFunc(handlers.Index))
diff --git a/templates/about.gotpl b/templates/about.gotpl
new file mode 100644
index 0000000..ff55b76
--- /dev/null
+++ b/templates/about.gotpl
@@ -0,0 +1,19 @@
+{{/*
+Copyright (C) 2025 Patrick "tyil" Spek <p.spek@tyil.nl>
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU Affero General Public License as
+published by the Free Software Foundation, either version 3 of the
+License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU Affero General Public License for more details.
+
+You should have received a copy of the GNU Affero General Public License
+along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/}}
+{{- block "main" . }}
+{{ .Body }}
+{{- end }}
diff --git a/templates/base.gotpl b/templates/base.gotpl
index 1a4923e..2d8575a 100644
--- a/templates/base.gotpl
+++ b/templates/base.gotpl
@@ -42,7 +42,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>.
{{- block "main" . }}<p>Nondescript.</p>{{ end }}
</main>
<footer>
- <p>Created by <a href="https://www.tyil.nl">tyil</a>, source code available through <a href="https://git.tyil.nl/dashlab">git</a> under the AGPL-3.0-or-later license.</p>
+ <a href="/about">About Dashlab</a>
</footer>
</body>
</html>