diff options
author | Brian Picciano <mediocregopher@gmail.com> | 2023-04-14 01:15:25 +0200 |
---|---|---|
committer | Brian Picciano <mediocregopher@gmail.com> | 2023-04-14 01:15:25 +0200 |
commit | 861070f74d75cd7b5ff4a410166b4df784b5b57f (patch) | |
tree | bc7ecea965667fbb5ffba27547231352fc597b90 /src | |
parent | 7d48d2abba46570ad67fa9f4b8c0b4e023fc2eed (diff) |
Prefix html title tag for posts with their title
Diffstat (limited to 'src')
-rw-r--r-- | src/http/posts.go | 5 | ||||
-rw-r--r-- | src/http/tpl.go | 15 | ||||
-rw-r--r-- | src/http/tpl/base.html | 2 |
3 files changed, 20 insertions, 2 deletions
diff --git a/src/http/posts.go b/src/http/posts.go index 2c6f896..872ea89 100644 --- a/src/http/posts.go +++ b/src/http/posts.go @@ -271,7 +271,10 @@ func (a *api) getPostHandler() http.Handler { return } - executeTemplate(rw, r, tpl, tplPayload) + executeTemplate( + rw, r, tpl, tplPayload, + executeTemplateWithTitlePrefix(storedPost.Title), + ) }) } 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), diff --git a/src/http/tpl/base.html b/src/http/tpl/base.html index fa65911..01b5386 100644 --- a/src/http/tpl/base.html +++ b/src/http/tpl/base.html @@ -2,7 +2,7 @@ <html> <head> - <title>mediocregopher's lil web corner</title> + <title>{{ .Title }}</title> <style>{{ StaticInlineCSS "new.css" }}</style> <style>{{ StaticInlineCSS "mediocre.css" }}</style> |