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
|
||||||
Taxonomies []*taxonomy `mapstructure:"taxonomies"`
|
Taxonomies []*taxonomy `mapstructure:"taxonomies"`
|
||||||
// Menus
|
// Menus
|
||||||
Menus []*menu `mapstructure:"menus"`
|
Menus map[string]*menu `mapstructure:"menus"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type section struct {
|
type section struct {
|
||||||
|
@ -63,7 +63,6 @@ type taxonomy struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type menu struct {
|
type menu struct {
|
||||||
Id string `mapstructure:"id"`
|
|
||||||
Items []*menuItem `mapstructure:"items"`
|
Items []*menuItem `mapstructure:"items"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -113,7 +112,7 @@ func initConfig() error {
|
||||||
viper.SetDefault("blog.pagination", 10)
|
viper.SetDefault("blog.pagination", 10)
|
||||||
viper.SetDefault("blog.sections", []*section{{Name: "posts", Title: "Posts", Description: "**Posts** on this blog"}})
|
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.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.nick", "admin")
|
||||||
viper.SetDefault("user.name", "Admin")
|
viper.SetDefault("user.name", "Admin")
|
||||||
viper.SetDefault("user.password", "secret")
|
viper.SetDefault("user.password", "secret")
|
||||||
|
|
|
@ -24,7 +24,7 @@ blog:
|
||||||
title: Tags
|
title: Tags
|
||||||
description: "**Tags** on this blog"
|
description: "**Tags** on this blog"
|
||||||
menus:
|
menus:
|
||||||
- id: main
|
main:
|
||||||
items:
|
items:
|
||||||
- title: Home
|
- title: Home
|
||||||
link: /
|
link: /
|
||||||
|
|
|
@ -27,12 +27,7 @@ func initRendering() {
|
||||||
return appConfig.Blog
|
return appConfig.Blog
|
||||||
},
|
},
|
||||||
"menu": func(id string) *menu {
|
"menu": func(id string) *menu {
|
||||||
for _, m := range appConfig.Blog.Menus {
|
return appConfig.Blog.Menus[id]
|
||||||
if m.Id == id {
|
|
||||||
return m
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
},
|
},
|
||||||
"md": func(content string) template.HTML {
|
"md": func(content string) template.HTML {
|
||||||
htmlContent, err := renderMarkdown(content)
|
htmlContent, err := renderMarkdown(content)
|
||||||
|
|
Loading…
Reference in New Issue