56 lines
1.0 KiB
Go
56 lines
1.0 KiB
Go
package server
|
|
|
|
import (
|
|
"embed"
|
|
"html/template"
|
|
)
|
|
|
|
//go:embed templates
|
|
var templateFS embed.FS
|
|
|
|
type Templates struct {
|
|
page *template.Template
|
|
search *template.Template
|
|
}
|
|
|
|
type PageData struct {
|
|
Title string
|
|
SiteTitle string
|
|
Body template.HTML
|
|
Nav template.HTML
|
|
PrevTitle string
|
|
PrevPath string
|
|
NextTitle string
|
|
NextPath string
|
|
}
|
|
|
|
type SearchData struct {
|
|
Title string
|
|
SiteTitle string
|
|
Query string
|
|
Results []SearchResult
|
|
Nav template.HTML
|
|
}
|
|
|
|
type SearchResult struct {
|
|
Title string
|
|
Path string
|
|
Snippet string
|
|
}
|
|
|
|
func LoadTemplates() (*Templates, error) {
|
|
funcs := template.FuncMap{}
|
|
|
|
page, err := template.New("page.html").Funcs(funcs).ParseFS(templateFS, "templates/base.html", "templates/page.html")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
search, err := template.New("search.html").Funcs(funcs).ParseFS(templateFS, "templates/base.html", "templates/search.html")
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
return &Templates{page: page, search: search}, nil
|
|
}
|