General rel=me support. Resolves #13

This commit is contained in:
Niko Abeler 2022-11-01 21:35:47 +01:00
parent 94918b5b62
commit 8c1d7fd8c7
3 changed files with 33 additions and 18 deletions

View File

@ -75,14 +75,10 @@
<img class="u-photo u-logo avatar" src="{{ .User.AvatarUrl }}" alt="{{ .User.Config.Title }}" width="100" height="100" /> <img class="u-photo u-logo avatar" src="{{ .User.AvatarUrl }}" alt="{{ .User.Config.Title }}" width="100" height="100" />
{{ end }} {{ end }}
<div style="float: right; list-style: none;"> <div style="float: right; list-style: none;">
{{ if .User.Config.TwitterHandle}} {{ range $me := .User.Config.Me }}
<li><a href="https://twitter.com/{{.User.Config.TwitterHandle}}" rel="me">@{{.User.Config.TwitterHandle}} on Twitter</a> <li><a href="{{$me.Url}}" rel="me">{{$me.Name}}</a>
</li> </li>
{{ end }} {{ end }}
{{ if .User.Config.GitHubHandle}}
<li><a href="https://github.com/{{.User.Config.GitHubHandle}}" rel="me">@{{.User.Config.GitHubHandle}} on GitHub</a>
</li>
{{ end }}
</div> </div>
</div> </div>

View File

@ -25,10 +25,14 @@ func TestCanRenderPost(t *testing.T) {
} }
func TestRenderTwitterHandle(t *testing.T) { func TestRenderOneMe(t *testing.T) {
user := getTestUser() user := getTestUser()
config, _ := user.Config() config, _ := user.Config()
config.TwitterHandle = "testhandle" config.Me = append(config.Me, owl.UserMe{
Name: "Twitter",
Url: "https://twitter.com/testhandle",
})
user.SetConfig(config) user.SetConfig(config)
post, _ := user.CreateNewPost("testpost", false) post, _ := user.CreateNewPost("testpost", false)
result, err := owl.RenderPost(post) 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() user := getTestUser()
config, _ := user.Config() 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) user.SetConfig(config)
post, _ := user.CreateNewPost("testpost", false) post, _ := user.CreateNewPost("testpost", false)
result, err := owl.RenderPost(post) result, err := owl.RenderPost(post)
@ -57,8 +69,11 @@ func TestRenderGitHubHandle(t *testing.T) {
return 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\"") { 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)
} }
} }

16
user.go
View File

@ -17,12 +17,16 @@ type User struct {
} }
type UserConfig struct { type UserConfig struct {
Title string `yaml:"title"` Title string `yaml:"title"`
SubTitle string `yaml:"subtitle"` SubTitle string `yaml:"subtitle"`
HeaderColor string `yaml:"header_color"` HeaderColor string `yaml:"header_color"`
TwitterHandle string `yaml:"twitter_handle"` AuthorName string `yaml:"author_name"`
GitHubHandle string `yaml:"github_handle"` Me []UserMe `yaml:"me"`
AuthorName string `yaml:"author_name"` }
type UserMe struct {
Name string `yaml:"name"`
Url string `yaml:"url"`
} }
func (user User) Dir() string { func (user User) Dir() string {