~adnano/astronaut

astronaut/templates.go -rw-r--r-- 612 bytes
947cfac7Adnan Maolood Update default bindings 17 days ago
                                                                                
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
package main

import (
	"crypto/x509"
	"embed"
	"text/template"

	"git.sr.ht/~adnano/go-gemini/tofu"
)

//go:embed about
var static embed.FS

var templates *template.Template

func init() {
	funcs := template.FuncMap{
		"host": func(hostname string, cert *x509.Certificate) tofu.Host {
			return tofu.NewHost(hostname, cert.Raw)
		},
		"title": func(err error) string {
			if title, ok := err.(interface {
				Title() string
			}); ok {
				return title.Title()
			}
			return ""
		},
	}
	templates = template.New("templates").Funcs(funcs)
	templates = template.Must(templates.ParseFS(static, "about/*.tmpl"))
}