{{if .Results}} {{range .Results}} - {{template "result_item" .}} + {{template (templateForResult .Template) .}} {{end}} {{else if not .Answers}}
diff --git a/internal/views/templates/video_item.html b/internal/views/templates/video_item.html new file mode 100644 index 0000000..0ca0109 --- /dev/null +++ b/internal/views/templates/video_item.html @@ -0,0 +1,22 @@ +{{define "video_item"}} +
+ {{if .Thumbnail}} +
+ + {{.Title}} + +
+ {{end}} +
+

+ {{.Title}} +

+ {{if .Content}} +

{{.Content}}

+ {{end}} + {{if .Engine}} +
{{.Engine}}
+ {{end}} +
+
+{{end}} diff --git a/internal/views/views.go b/internal/views/views.go index c9e371e..5592235 100644 --- a/internal/views/views.go +++ b/internal/views/views.go @@ -63,16 +63,24 @@ func init() { funcMap := template.FuncMap{ "urlquery": template.URLQueryEscaper, + // templateForResult returns the template name to use for a result. + // Defaults to "result_item"; use "video_item" for video results. + "templateForResult": func(tmpl string) string { + if tmpl == "videos" { + return "video_item" + } + return "result_item" + }, } tmplFull = template.Must(template.New("").Funcs(funcMap).ParseFS(tmplFS, - "base.html", "results.html", "results_inner.html", "result_item.html", + "base.html", "results.html", "results_inner.html", "result_item.html", "video_item.html", )) tmplIndex = template.Must(template.New("").Funcs(funcMap).ParseFS(tmplFS, "base.html", "index.html", )) tmplFragment = template.Must(template.New("").Funcs(funcMap).ParseFS(tmplFS, - "results_inner.html", "result_item.html", + "results_inner.html", "result_item.html", "video_item.html", )) }