footer menu

This commit is contained in:
Niko Abeler 2022-12-04 19:51:53 +01:00
parent 8f2e2cd5f6
commit a717164334
3 changed files with 54 additions and 0 deletions

View File

@ -108,6 +108,19 @@
{{ .Content }} {{ .Content }}
</main> </main>
<footer class="container"> <footer class="container">
<nav>
<ul>
{{ range $link := .User.Config.FooterMenu }}
{{ if $link.List }}
<li><a href="{{ listUrl $.User $link.List }}">{{ $link.Title }}</a></li>
{{ else if $link.Post }}
<li><a href="{{ postUrl $.User $link.Post }}">{{ $link.Title }}</a></li>
{{ else }}
<li><a href="{{ $link.Url }}">{{ $link.Title }}</a></li>
{{ end }}
{{ end }}
</ul>
</nav>
</footer> </footer>
</body> </body>

View File

@ -448,3 +448,37 @@ func TestRenderHeaderMenuPost(t *testing.T) {
assertions.AssertContains(t, result, "Test Entry") assertions.AssertContains(t, result, "Test Entry")
assertions.AssertContains(t, result, post.UrlPath()) assertions.AssertContains(t, result, post.UrlPath())
} }
func TestRenderFooterMenuListItem(t *testing.T) {
user := getTestUser()
user.AddFooterMenuItem(owl.MenuItem{
Title: "Test Entry",
List: "test",
})
result, _ := owl.RenderIndexPage(user)
assertions.AssertContains(t, result, "Test Entry")
assertions.AssertContains(t, result, "/lists/test")
}
func TestRenderFooterMenuUrlItem(t *testing.T) {
user := getTestUser()
user.AddFooterMenuItem(owl.MenuItem{
Title: "Test Entry",
Url: "https://example.com",
})
result, _ := owl.RenderIndexPage(user)
assertions.AssertContains(t, result, "Test Entry")
assertions.AssertContains(t, result, "https://example.com")
}
func TestRenderFooterMenuPost(t *testing.T) {
user := getTestUser()
post, _ := user.CreateNewPost("testpost", false)
user.AddFooterMenuItem(owl.MenuItem{
Title: "Test Entry",
Post: post.Id(),
})
result, _ := owl.RenderIndexPage(user)
assertions.AssertContains(t, result, "Test Entry")
assertions.AssertContains(t, result, post.UrlPath())
}

View File

@ -29,6 +29,7 @@ type UserConfig struct {
Lists []PostList `yaml:"lists"` Lists []PostList `yaml:"lists"`
PrimaryListInclude []string `yaml:"primary_list_include"` PrimaryListInclude []string `yaml:"primary_list_include"`
HeaderMenu []MenuItem `yaml:"header_menu"` HeaderMenu []MenuItem `yaml:"header_menu"`
FooterMenu []MenuItem `yaml:"footer_menu"`
} }
type PostList struct { type PostList struct {
@ -404,6 +405,12 @@ func (user User) AddHeaderMenuItem(link MenuItem) error {
return user.SetConfig(config) return user.SetConfig(config)
} }
func (user User) AddFooterMenuItem(link MenuItem) error {
config := user.Config()
config.FooterMenu = append(config.FooterMenu, link)
return user.SetConfig(config)
}
func (user User) ResetPassword(password string) error { func (user User) ResetPassword(password string) error {
bytes, err := bcrypt.GenerateFromPassword([]byte(password), 10) bytes, err := bcrypt.GenerateFromPassword([]byte(password), 10)
if err != nil { if err != nil {