From 861070f74d75cd7b5ff4a410166b4df784b5b57f Mon Sep 17 00:00:00 2001 From: Brian Picciano Date: Fri, 14 Apr 2023 01:15:25 +0200 Subject: Prefix html title tag for posts with their title --- src/http/tpl.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/http/tpl.go') diff --git a/src/http/tpl.go b/src/http/tpl.go index 0f6b531..bb5750d 100644 --- a/src/http/tpl.go +++ b/src/http/tpl.go @@ -133,11 +133,21 @@ func (a *api) mustParseBasedTpl(name string) *template.Template { type tplData struct { Payload interface{} + Title string } func newTPLData(r *http.Request, payload interface{}) tplData { return tplData{ Payload: payload, + Title: "mediocregopher's lil web corner", + } +} + +type executeTemplateOpt func(*tplData) + +func executeTemplateWithTitlePrefix(prefix string) executeTemplateOpt { + return func(d *tplData) { + d.Title = prefix + " - " + d.Title } } @@ -145,10 +155,15 @@ func newTPLData(r *http.Request, payload interface{}) tplData { func executeTemplate( rw http.ResponseWriter, r *http.Request, tpl *template.Template, payload interface{}, + opts ...executeTemplateOpt, ) { tplData := newTPLData(r, payload) + for _, opt := range opts { + opt(&tplData) + } + if err := tpl.Execute(rw, tplData); err != nil { apiutil.InternalServerError( rw, r, fmt.Errorf("rendering template: %w", err), -- cgit v1.2.3