blob: ee7ddf5763e1258330cd07478152e25ec702eda7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
package handlers
import (
"net/http"
"git.leonardobishop.net/history/pkg/entries"
"git.leonardobishop.net/history/pkg/html"
)
const style = `<style>
html, body {
text-size-adjust: none;
}
body {
max-width: 800px;
margin: 0 auto;
}
.entry-group {
display: flex;
flex-direction: column;
gap: 0.5rem;
}
.entry {
display: grid;
grid-template:
'title date'
'desc desc';
}
.entry-title {
grid-area: title;
font-size: medium;
}
.entry-date {
grid-area: date;
justify-self: end;
font-size: medium;
}
.entry-description {
grid-area: desc;
font-size: small;
}
</style>`
func GetEntriesHtml(entriesService entries.Service, htmlService html.Service) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
entries, err := entriesService.GetEntries()
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}
html, err := htmlService.GenerateHtml(entries)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
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))
}
}
|