aboutsummaryrefslogtreecommitdiff
path: root/backend/home.go
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <william@herges.fr>2025-10-02 22:35:58 +0200
committerAnhgelus Morhtuuzh <william@herges.fr>2025-10-02 22:35:58 +0200
commit6044dd841c81f0f4d206c6c8800b0fd30320cf13 (patch)
tree7498d483e661e0c87d3af2f7ab03eacda48fe30b /backend/home.go
parent5dfd71bfe1c0e25da413f00256a302b13c88d26d (diff)
feat(backend): display list of logs in home
Diffstat (limited to 'backend/home.go')
-rw-r--r--backend/home.go36
1 files changed, 35 insertions, 1 deletions
diff --git a/backend/home.go b/backend/home.go
index 41f2fe5..32634a1 100644
--- a/backend/home.go
+++ b/backend/home.go
@@ -1,13 +1,47 @@
package backend
import (
+ "maps"
"net/http"
+ "slices"
+ "time"
"github.com/go-chi/chi/v5"
)
+var sortedLogs []*logData
+
+type homeData struct {
+ *data
+ Logs []*logData
+}
+
+func (h *homeData) SetData(d *data) {
+ h.data = d
+}
+
func HandleHome(r *chi.Mux) {
r.Get("/", func(w http.ResponseWriter, r *http.Request) {
- new(data).handleGeneric(w, r, "home", nil)
+ d := new(homeData)
+ d.data = new(data)
+ if sortedLogs == nil {
+ sortLogs()
+ }
+ d.Logs = sortedLogs
+ d.handleGeneric(w, r, "home", d)
+ })
+}
+
+func sortLogs() {
+ slices.SortedFunc(maps.Values(logs), func(l *logData, l2 *logData) int {
+ lt := l.pubDate.AsTime(time.UTC)
+ l2t := l2.pubDate.AsTime(time.UTC)
+ // we want it reversed
+ if lt.Before(l2t) {
+ return 1
+ } else if lt.After(l2t) {
+ return -1
+ }
+ return 0
})
}