1This is a base page template. All the other template pages implement this interface.
2
3{% import "context" %}
4{% import "crypto/rand" %}
5{% import "encoding/hex" %}
6{% import "strconv" %}
7{% import "time" %}
8
9{% code
10
11 var Slug = ""
12 var Session = ""
13
14 func init() {
15 Session = hex.EncodeToString(generateSmallTimeID())
16}
17
18func generateSmallTimeID() []byte {
19 b := make([]byte, 4)
20 _, err := rand.Read(b)
21 if err != nil {
22 panic(err)
23 }
24 return b
25}
26%}
27
28{% interface
29Page {
30 Title(ctx context.Context)
31 Content(ctx context.Context)
32 Script(ctx context.Context)
33 Navbar(ctx context.Context)
34}
35%}
36
37
38{% code func FromUInttoString(u *uint) string {
39 if u != nil {
40 return strconv.FormatUint(uint64(*u), 10)
41 }
42 return ""
43 }
44%}
45
46
47
48{% code func TimeFormat(t time.Time) string {
49 return t.Format("02.01.2006")
50 }
51%}
52
53{% code func Ignore[T any](v T, _ error) T {
54 return v
55 }
56%}
57
58
59{% code func IsAuthenticationDisabled(ctx context.Context) bool {
60 t, ok := ctx.Value("disableAuthentication").(bool)
61 return ok && t
62 }
63%}
64
65{% code func IsLoggedIn(ctx context.Context) bool {
66 t, ok := ctx.Value("logged").(bool)
67 return ok && t
68 }
69%}
70
71Page prints a page implementing Page interface.
72{% func PageTemplate(p Page, ctx context.Context) %}
73<!DOCTYPE html>
74<html lang="en" data-bs-theme="light">
75 <head>
76 <meta charset="utf-8">
77 <link rel="icon" href="data:,">
78 <title>{%= p.Title(ctx) %}</title>
79 <link rel="stylesheet" href="/static/main{%s Slug %}.css">
80 <link rel="stylesheet" href="/static/theme.{%s Session %}{%s Slug %}.css">
81 <html data-bs-theme="dark">
82 <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
83 <meta name="viewport" content="width=device-width, initial-scale=1" />
84 </head>
85 <body>
86 {%= p.Navbar(ctx) %}
87 <div class="container">
88 {%= p.Content(ctx) %}
89 </div>
90 </body>
91 {%= p.Script(ctx) %}
92 <script>
93 function a(){const e=window.matchMedia("(prefers-color-scheme: dark)").matches;document.documentElement.setAttribute("data-bs-theme",e?"dark":"light")}a(),window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change",a);
94 </script>
95</html>
96{% endfunc %}