Refactor Layout and improve search
This commit is contained in:
@@ -17,7 +17,11 @@ import (
|
||||
//go:embed assets
|
||||
var assets embed.FS
|
||||
|
||||
var tmpl = template.Must(template.New("page.html").ParseFS(assets, "assets/page.html"))
|
||||
var (
|
||||
pageTmpl = template.Must(template.ParseFS(assets, "assets/layout.html", "assets/page.html"))
|
||||
editTmpl = template.Must(template.ParseFS(assets, "assets/layout.html", "assets/edit.html"))
|
||||
searchTmpl = template.Must(template.ParseFS(assets, "assets/layout.html", "assets/search.html"))
|
||||
)
|
||||
|
||||
// specialPage is the result returned by a pageTypeHandler.
|
||||
// Content is injected into the page after the standard markdown content.
|
||||
@@ -226,7 +230,11 @@ func (h *handler) serveDir(w http.ResponseWriter, r *http.Request, urlPath, fsPa
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||
if err := tmpl.Execute(w, data); err != nil {
|
||||
t := pageTmpl
|
||||
if editMode {
|
||||
t = editTmpl
|
||||
}
|
||||
if err := t.ExecuteTemplate(w, "layout", data); err != nil {
|
||||
log.Printf("template error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user