From 63f89491f36b719c864f975ba355e209fbbcbf5a Mon Sep 17 00:00:00 2001 From: Niko Abeler Date: Tue, 6 Sep 2022 21:32:31 +0200 Subject: [PATCH] twitter handle + refactor user config in renderer --- embed/initial/base.html | 19 ++++++++++++++++--- renderer.go | 12 +++++------- renderer_test.go | 19 +++++++++++++++++++ user.go | 7 ++++--- 4 files changed, 44 insertions(+), 13 deletions(-) diff --git a/embed/initial/base.html b/embed/initial/base.html index 2fb6cb4..5e701b1 100644 --- a/embed/initial/base.html +++ b/embed/initial/base.html @@ -10,9 +10,15 @@ @@ -23,8 +29,8 @@ @@ -35,6 +41,13 @@ {{ .Content }} diff --git a/renderer.go b/renderer.go index a1b7643..7781ce3 100644 --- a/renderer.go +++ b/renderer.go @@ -50,16 +50,14 @@ func renderIntoBaseTemplate(user User, data PageContent) (string, error) { Title string Content template.HTML User User - UserTitle string + UserConfig UserConfig UserSubtitle string HeaderColor string }{ - Title: data.Title, - Content: data.Content, - User: user, - UserTitle: user_config.Title, - UserSubtitle: user_config.SubTitle, - HeaderColor: user_config.HeaderColor, + Title: data.Title, + Content: data.Content, + User: user, + UserConfig: user_config, } var html bytes.Buffer diff --git a/renderer_test.go b/renderer_test.go index f36aacb..5f80e6e 100644 --- a/renderer_test.go +++ b/renderer_test.go @@ -25,6 +25,25 @@ func TestCanRenderPost(t *testing.T) { } +func TestRenderTwitterHandle(t *testing.T) { + user := getTestUser() + config, _ := user.Config() + config.TwitterHandle = "testhandle" + user.SetConfig(config) + post, _ := user.CreateNewPost("testpost") + result, err := owl.RenderPost(&post) + + if err != nil { + t.Error("Error rendering post: " + err.Error()) + return + } + + if !strings.Contains(result, "href=\"https://twitter.com/testhandle\" rel=\"me\"") { + t.Error("Twitter handle not rendered. Got: " + result) + } + +} + func TestRenderPostHEntry(t *testing.T) { user := getTestUser() post, _ := user.CreateNewPost("testpost") diff --git a/user.go b/user.go index 82a9859..b9eeaa4 100644 --- a/user.go +++ b/user.go @@ -18,9 +18,10 @@ type User struct { } type UserConfig struct { - Title string `yaml:"title"` - SubTitle string `yaml:"subtitle"` - HeaderColor string `yaml:"header_color"` + Title string `yaml:"title"` + SubTitle string `yaml:"subtitle"` + HeaderColor string `yaml:"header_color"` + TwitterHandle string `yaml:"twitter_handle"` } func (user User) Dir() string {