Fix kinds/types - templates mapping

This commit is contained in:
Daniele Tonon
2023-05-27 14:45:32 +02:00
parent 11e96a0d73
commit 25eaad1595

View File

@@ -185,6 +185,17 @@ func render(w http.ResponseWriter, r *http.Request) {
"eventJSON": string(eventJSON),
}
// Use a mapping to expressly link the templates and share them between more kinds/types
template_mapping := make(map[string]string)
template_mapping["profile"] = "profile.html"
template_mapping["note"] = "note.html"
template_mapping["address"] = "raw.html"
// If a mapping is not found fallback to raw
if template_mapping[typ] == "" {
template_mapping[typ] = "raw.html"
}
funcMap := template.FuncMap{
"BasicFormatting": BasicFormatting,
"SanitizeString": html.EscapeString,
@@ -196,7 +207,7 @@ func render(w http.ResponseWriter, r *http.Request) {
ParseFS(templates, "templates/*"),
)
if err := tmpl.ExecuteTemplate(w, "note.html", params); err != nil {
if err := tmpl.ExecuteTemplate(w, template_mapping[typ], params); err != nil {
log.Error().Err(err).Msg("error rendering")
return
}