summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeonardo Bishop <me@leonardobishop.net>2025-09-10 00:46:42 +0100
committerLeonardo Bishop <me@leonardobishop.net>2025-09-10 00:46:42 +0100
commitd122d841e8b7dd7f8942b6f2fa84220f95f2cae4 (patch)
treea00734c1109b222f2485bd31c61fdf5e00a6d516
parentbaea81484f61fc341634ecf5e144d7ecf18ad42f (diff)
Add optional CSS to html
-rw-r--r--.gitignore2
-rw-r--r--api/handlers/html.go36
-rw-r--r--api/handlers/pong.go31
-rw-r--r--api/router.go1
-rw-r--r--pkg/html/service.go11
5 files changed, 77 insertions, 4 deletions
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 = `<style>
+.entry {
+ display: grid;
+ grid-template:
+ 'title date'
+ 'desc desc';
+}
+
+.entry-title {
+ grid-area: title;
+}
+
+.entry-date {
+ grid-area: date;
+ justify-self: end;
+}
+
+.entry-description {
+ grid-area: desc;
+}
+</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 = `<!DOCTYPE html>
+<html>
+<head>
+<title>History</title>
+` + style + `
+</head>
+<body>` + html + `</body>
+</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 = `<!DOCTYPE html>
+<html>
+<head>
+<title>Pong!</title>
+</head>
+<body>
+<pre>
+ _______
+< Pong! >
+ -------
+ \ ^__^
+ \ (oo)\_______
+ (__)\ )\/\
+ ||----w |
+ || ||
+</pre>
+</body>
+</html>`
+
+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 += "<span class=\"entry\">"
+ str += "<a class=\"entry-title\" href=" + entry.Url + " target=\"_blank\">"
if entry.KindName == "starred" {
str += "<b>"
}
- str += "<a class=\"entry-title\" href=" + entry.Url + " target=\"_blank\">" + entry.KindEmoji + " " + entry.Title + "</a>"
+ str += entry.KindEmoji + " " + entry.Title
if entry.KindName == "starred" {
str += "</b>"
}
- str += " - <span class=\"entry-description\">" + entry.Description + "</span>"
- str += " - <span class=\"entry-date\">" + date.Format(time.DateOnly) + "</span>"
- str += "</span><br>"
+ str += "</a>"
+
+ str += "<span class=\"entry-description\">" + entry.Description + "</span>"
+ str += "<i class=\"entry-date\">on " + date.Format("02 Jan 2006") + "</i>"
+ str += "</span>"
}
return str, nil