-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.go
More file actions
42 lines (34 loc) · 1.11 KB
/
template.go
File metadata and controls
42 lines (34 loc) · 1.11 KB
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
package main
import (
"bytes"
"embed"
"html/template"
"log"
)
// larkHTMLTemplate is a CalcMark-branded HTML template that replaces the
// default blue-themed template. It uses CalcMark design tokens (purple accent,
// Inter + JetBrains Mono fonts) and supports dark mode via prefers-color-scheme.
//
//go:embed lark.gohtml
var larkHTMLTemplate string
//go:embed templates
var templateFS embed.FS
// pageTemplates holds pre-rendered page HTML keyed by page name.
var pageTemplates = map[string]string{}
func init() {
layout := template.Must(template.ParseFS(templateFS, "templates/layout.gohtml"))
pages := []string{"index", "about"}
for _, page := range pages {
// Clone layout and parse the page-specific blocks into it.
t := template.Must(template.Must(layout.Clone()).ParseFS(templateFS, "templates/"+page+".gohtml"))
var buf bytes.Buffer
if err := t.ExecuteTemplate(&buf, "layout", nil); err != nil {
log.Fatalf("render %s: %v", page, err)
}
pageTemplates[page] = buf.String()
}
}
// getPage returns the pre-rendered HTML for a page.
func getPage(name string) string {
return pageTemplates[name]
}