From d122d841e8b7dd7f8942b6f2fa84220f95f2cae4 Mon Sep 17 00:00:00 2001 From: Leonardo Bishop Date: Wed, 10 Sep 2025 00:46:42 +0100 Subject: Add optional CSS to html --- .gitignore | 2 ++ api/handlers/html.go | 36 ++++++++++++++++++++++++++++++++++++ api/handlers/pong.go | 31 +++++++++++++++++++++++++++++++ api/router.go | 1 + pkg/html/service.go | 11 +++++++---- 5 files changed, 77 insertions(+), 4 deletions(-) create mode 100644 api/handlers/pong.go diff --git a/.gitignore b/.gitignore index f4bd7de..139b7e9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ history database.db +config.yaml + diff --git a/api/handlers/html.go b/api/handlers/html.go index dd5d4e8..2f6688c 100644 --- a/api/handlers/html.go +++ b/api/handlers/html.go @@ -7,6 +7,28 @@ import ( "git.leonardobishop.net/history/pkg/html" ) +const style = `` + func GetEntriesHtml(entriesService entries.Service, htmlService html.Service) http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { entries, err := entriesService.GetEntries() @@ -21,6 +43,20 @@ func GetEntriesHtml(entriesService entries.Service, htmlService html.Service) ht return } + if r.URL.Query().Get("css") == "no" { + goto send + } + + html = ` + + +History +` + style + ` + +` + html + ` +` + + send: w.Header().Set("Content-Type", "text/html;charset=UTF-8") w.Write([]byte(html)) } diff --git a/api/handlers/pong.go b/api/handlers/pong.go new file mode 100644 index 0000000..ee0d445 --- /dev/null +++ b/api/handlers/pong.go @@ -0,0 +1,31 @@ +package handlers + +import ( + "net/http" +) + +const pong = ` + + +Pong! + + +
+ _______
+< Pong! >
+ -------
+        \   ^__^
+         \  (oo)\_______
+            (__)\       )\/\
+                ||----w |
+                ||     ||
+
+ +` + +func Pong() http.HandlerFunc { + return func(w http.ResponseWriter, r *http.Request) { + w.Header().Set("Content-Type", "text/html") + w.Write([]byte(pong)) + } +} diff --git a/api/router.go b/api/router.go index ec7ac4d..c18fed8 100644 --- a/api/router.go +++ b/api/router.go @@ -22,6 +22,7 @@ func NewServer(api ApiServices) *http.ServeMux { mux.HandleFunc("POST /record", middleware.Cors(handlers.RecordEntry(api.EntiresService, api.Config.Token))) mux.HandleFunc("GET /html", handlers.GetEntriesHtml(api.EntiresService, api.HtmlService)) + mux.HandleFunc("GET /", handlers.Pong()) return mux } diff --git a/pkg/html/service.go b/pkg/html/service.go index cba3a6c..8a7a163 100644 --- a/pkg/html/service.go +++ b/pkg/html/service.go @@ -34,16 +34,19 @@ func (s *service) GenerateHtml(entries []sqlc.GetEntriesRow) (string, error) { currentDate = date str += "" + str += "" if entry.KindName == "starred" { str += "" } - str += "" + entry.KindEmoji + " " + entry.Title + "" + str += entry.KindEmoji + " " + entry.Title if entry.KindName == "starred" { str += "" } - str += " - " + entry.Description + "" - str += " - " + date.Format(time.DateOnly) + "" - str += "
" + str += "" + + str += "" + entry.Description + "" + str += "on " + date.Format("02 Jan 2006") + "" + str += "" } return str, nil -- cgit v1.2.3-70-g09d2