twitter handle + refactor user config in renderer

This commit is contained in:
Niko Abeler 2022-09-06 21:32:31 +02:00
parent 5596b578f4
commit 63f89491f3
4 changed files with 44 additions and 13 deletions

View File

@ -10,9 +10,15 @@
<link rel="webmention" href="{{ .User.WebmentionUrl }}">
<style>
header {
background-color: {{.HeaderColor}};
background-color: {{.UserConfig.HeaderColor}};
}
footer {
border-top: dashed 2px;
border-color: #ccc;
}
hgroup h2 a { color: inherit; }
</style>
</head>
@ -23,8 +29,8 @@
<ul>
<li>
<hgroup>
<h2><a href="{{ .User.UrlPath }}">{{ .UserTitle }}</a></h2>
<h3>{{ .UserSubtitle }}</h3>
<h2><a href="{{ .User.UrlPath }}">{{ .UserConfig.Title }}</a></h2>
<h3>{{ .UserConfig.SubTitle }}</h3>
</hgroup>
</li>
</ul>
@ -35,6 +41,13 @@
{{ .Content }}
</main>
<footer class="container">
<nav>
<ul>
{{ if .UserConfig.TwitterHandle}}
<li><a href="https://twitter.com/{{.UserConfig.TwitterHandle}}" rel="me">@{{.UserConfig.TwitterHandle}} on Twitter</a></li>
{{ end }}
</ul>
</nav>
</footer>
</body>

View File

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

View File

@ -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")

View File

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