From 8c1d7fd8c70bbcd8d5eb7ea41fa20883c5c6d807 Mon Sep 17 00:00:00 2001 From: Niko Abeler Date: Tue, 1 Nov 2022 21:35:47 +0100 Subject: [PATCH] General rel=me support. Resolves #13 --- embed/initial/base.html | 10 +++------- renderer_test.go | 25 ++++++++++++++++++++----- user.go | 16 ++++++++++------ 3 files changed, 33 insertions(+), 18 deletions(-) diff --git a/embed/initial/base.html b/embed/initial/base.html index 2afa524..2c2493b 100644 --- a/embed/initial/base.html +++ b/embed/initial/base.html @@ -75,14 +75,10 @@ {{ end }}
- {{ if .User.Config.TwitterHandle}} -
  • @{{.User.Config.TwitterHandle}} on Twitter + {{ range $me := .User.Config.Me }} +
  • {{$me.Name}}
  • - {{ end }} - {{ if .User.Config.GitHubHandle}} -
  • @{{.User.Config.GitHubHandle}} on GitHub -
  • - {{ end }} + {{ end }}
    diff --git a/renderer_test.go b/renderer_test.go index c46d0e5..6068ec5 100644 --- a/renderer_test.go +++ b/renderer_test.go @@ -25,10 +25,14 @@ func TestCanRenderPost(t *testing.T) { } -func TestRenderTwitterHandle(t *testing.T) { +func TestRenderOneMe(t *testing.T) { user := getTestUser() config, _ := user.Config() - config.TwitterHandle = "testhandle" + config.Me = append(config.Me, owl.UserMe{ + Name: "Twitter", + Url: "https://twitter.com/testhandle", + }) + user.SetConfig(config) post, _ := user.CreateNewPost("testpost", false) result, err := owl.RenderPost(post) @@ -44,10 +48,18 @@ func TestRenderTwitterHandle(t *testing.T) { } -func TestRenderGitHubHandle(t *testing.T) { +func TestRenderTwoMe(t *testing.T) { user := getTestUser() config, _ := user.Config() - config.GitHubHandle = "testhandle" + config.Me = append(config.Me, owl.UserMe{ + Name: "Twitter", + Url: "https://twitter.com/testhandle", + }) + config.Me = append(config.Me, owl.UserMe{ + Name: "Github", + Url: "https://github.com/testhandle", + }) + user.SetConfig(config) post, _ := user.CreateNewPost("testpost", false) result, err := owl.RenderPost(post) @@ -57,8 +69,11 @@ func TestRenderGitHubHandle(t *testing.T) { return } + if !strings.Contains(result, "href=\"https://twitter.com/testhandle\" rel=\"me\"") { + t.Error("Twitter handle not rendered. Got: " + result) + } if !strings.Contains(result, "href=\"https://github.com/testhandle\" rel=\"me\"") { - t.Error("GitHub handle not rendered. Got: " + result) + t.Error("Github handle not rendered. Got: " + result) } } diff --git a/user.go b/user.go index 14f0be9..fb7d4f0 100644 --- a/user.go +++ b/user.go @@ -17,12 +17,16 @@ type User struct { } type UserConfig struct { - Title string `yaml:"title"` - SubTitle string `yaml:"subtitle"` - HeaderColor string `yaml:"header_color"` - TwitterHandle string `yaml:"twitter_handle"` - GitHubHandle string `yaml:"github_handle"` - AuthorName string `yaml:"author_name"` + Title string `yaml:"title"` + SubTitle string `yaml:"subtitle"` + HeaderColor string `yaml:"header_color"` + AuthorName string `yaml:"author_name"` + Me []UserMe `yaml:"me"` +} + +type UserMe struct { + Name string `yaml:"name"` + Url string `yaml:"url"` } func (user User) Dir() string {