mirror of https://github.com/jlelse/GoBlog
Make menu config map, not list
This commit is contained in:
parent
bba5eaa078
commit
bf28e34038
|
@ -47,7 +47,7 @@ type configBlog struct {
|
|||
// Taxonomies
|
||||
Taxonomies []*taxonomy `mapstructure:"taxonomies"`
|
||||
// Menus
|
||||
Menus []*menu `mapstructure:"menus"`
|
||||
Menus map[string]*menu `mapstructure:"menus"`
|
||||
}
|
||||
|
||||
type section struct {
|
||||
|
@ -63,7 +63,6 @@ type taxonomy struct {
|
|||
}
|
||||
|
||||
type menu struct {
|
||||
Id string `mapstructure:"id"`
|
||||
Items []*menuItem `mapstructure:"items"`
|
||||
}
|
||||
|
||||
|
@ -113,7 +112,7 @@ func initConfig() error {
|
|||
viper.SetDefault("blog.pagination", 10)
|
||||
viper.SetDefault("blog.sections", []*section{{Name: "posts", Title: "Posts", Description: "**Posts** on this blog"}})
|
||||
viper.SetDefault("blog.taxonomies", []*taxonomy{{Name: "tags", Title: "Tags", Description: "**Tags** on this blog"}})
|
||||
viper.SetDefault("blog.menus", []*menu{{Id: "main", Items: []*menuItem{{Title: "Home", Link: "/"}, {Title: "Post", Link: "Posts"}}}})
|
||||
viper.SetDefault("blog.menus", map[string]*menu{"main": {Items: []*menuItem{{Title: "Home", Link: "/"}, {Title: "Post", Link: "Posts"}}}})
|
||||
viper.SetDefault("user.nick", "admin")
|
||||
viper.SetDefault("user.name", "Admin")
|
||||
viper.SetDefault("user.password", "secret")
|
||||
|
|
|
@ -24,7 +24,7 @@ blog:
|
|||
title: Tags
|
||||
description: "**Tags** on this blog"
|
||||
menus:
|
||||
- id: main
|
||||
main:
|
||||
items:
|
||||
- title: Home
|
||||
link: /
|
||||
|
|
|
@ -27,12 +27,7 @@ func initRendering() {
|
|||
return appConfig.Blog
|
||||
},
|
||||
"menu": func(id string) *menu {
|
||||
for _, m := range appConfig.Blog.Menus {
|
||||
if m.Id == id {
|
||||
return m
|
||||
}
|
||||
}
|
||||
return nil
|
||||
return appConfig.Blog.Menus[id]
|
||||
},
|
||||
"md": func(content string) template.HTML {
|
||||
htmlContent, err := renderMarkdown(content)
|
||||
|
|
Loading…
Reference in New Issue