feat: metadata draft

This commit is contained in:
2026-02-03 09:04:11 +01:00
parent 7238d02a13
commit d6617cec02
7 changed files with 58 additions and 45 deletions

View File

@ -67,7 +67,7 @@ func (tm *TemplateManager) GetTemplate(td *TemplateData) (*template.Template, er
return tmpl, nil
}
func (tm *TemplateManager) Render(w http.ResponseWriter, name string, data interface{}) error {
func (tm *TemplateManager) Render(w http.ResponseWriter, name string, data any) error {
// Build the template files - include all necessary templates
var files []string
@ -77,6 +77,9 @@ func (tm *TemplateManager) Render(w http.ResponseWriter, name string, data inter
// Include noteList template (used by index)
files = append(files, tm.buildTemplatePath("noteList"))
// Include metadata template
files = append(files, tm.buildTemplatePath("metadata"))
// Add the specific template
files = append(files, tm.buildTemplatePath(name))

View File

@ -100,6 +100,7 @@ func TestTemplateManagerRender(t *testing.T) {
writeTemplate(t, baseDir, "base.tmpl", `{{ define "base" }}<html>{{ template "content" . }}</html>{{ end }}`)
writeTemplate(t, baseDir, "noteList.tmpl", `{{ define "noteList" }}notes{{ end }}`)
writeTemplate(t, baseDir, "index.tmpl", `{{ define "content" }}hello{{ end }}`)
writeTemplate(t, baseDir, "metadata.tmpl", `{{ define "noteList" }}notes{{ end }}`)
tm := NewTemplateManager(baseDir)
rec := httptest.NewRecorder()
@ -126,6 +127,7 @@ func TestTemplateManagerRender_MissingTemplate(t *testing.T) {
baseDir := t.TempDir()
writeTemplate(t, baseDir, "base.tmpl", `{{ define "base" }}<html>{{ template "content" . }}</html>{{ end }}`)
writeTemplate(t, baseDir, "noteList.tmpl", `{{ define "noteList" }}notes{{ end }}`)
writeTemplate(t, baseDir, "metadata.tmpl", `{{ define "noteList" }}notes{{ end }}`)
tm := NewTemplateManager(baseDir)
rec := httptest.NewRecorder()