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" />
{{ end }}
<div style="float: right; list-style: none;">
{{ if .User.Config.TwitterHandle}}
<li><a href="https://twitter.com/{{.User.Config.TwitterHandle}}" rel="me">@{{.User.Config.TwitterHandle}} on Twitter</a>
{{ range $me := .User.Config.Me }}
<li><a href="{{$me.Url}}" rel="me">{{$me.Name}}</a>
</li>
{{ end }}
{{ if .User.Config.GitHubHandle}}
<li><a href="https://github.com/{{.User.Config.GitHubHandle}}" rel="me">@{{.User.Config.GitHubHandle}} on GitHub</a>
</li>
{{ end }}
{{ end }}
</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()
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)
}
}

16
user.go
View File

@ -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 {