This commit is contained in:
Jan-Lukas Else 2020-09-19 13:37:58 +02:00
parent 21670a0ccc
commit f38e8e5a20
6 changed files with 49 additions and 3 deletions

View File

@ -46,6 +46,8 @@ type configBlog struct {
Sections []*section `mapstructure:"sections"`
// Taxonomies
Taxonomies []*taxonomy `mapstructure:"taxonomies"`
// Menus
Menus []*menu `mapstructure:"menus"`
}
type section struct {
@ -60,6 +62,16 @@ type taxonomy struct {
Description string `mapstructure:"description"`
}
type menu struct {
Id string `mapstructure:"id"`
Items []*menuItem `mapstructure:"items"`
}
type menuItem struct {
Title string `mapstructure:"title"`
Link string `mapstructure:"link"`
}
type configUser struct {
Nick string `mapstructure:"nick"`
Name string `mapstructure:"name"`
@ -101,6 +113,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("user.nick", "admin")
viper.SetDefault("user.name", "Admin")
viper.SetDefault("user.password", "secret")

View File

@ -23,6 +23,13 @@ blog:
- name: tags
title: Tags
description: "**Tags** on this blog"
menus:
- id: main
items:
- title: Home
link: /
- title: Posts
link: /posts
user:
nick: admin
name: Admin

View File

@ -130,8 +130,9 @@ func serveIndex(path string, sec *section, tax *taxonomy, taxonomyValue string,
title = sec.Title
description = sec.Description
} else if tax == nil && sec == nil {
title = appConfig.Blog.Title
description = appConfig.Blog.Description
// Show no title or description on home
// title = appConfig.Blog.Title
// description = appConfig.Blog.Description
}
// Check if feed
if ft != NONE {

View File

@ -16,6 +16,7 @@ const templateRedirect = "redirect"
const templateIndex = "index"
const templateSummary = "summary"
const templateTaxonomy = "taxonomy"
const templateMenu = "menu"
var templates map[string]*template.Template
var templateFunctions template.FuncMap
@ -25,6 +26,14 @@ func initRendering() {
"blog": func() *configBlog {
return appConfig.Blog
},
"menu": func(id string) *menu {
for _, m := range appConfig.Blog.Menus {
if m.Id == id {
return m
}
}
return nil
},
"md": func(content string) template.HTML {
htmlContent, err := renderMarkdown(content)
if err != nil {
@ -64,7 +73,7 @@ func initRendering() {
}
templates = make(map[string]*template.Template)
for _, name := range []string{templatePost, templateError, templateRedirect, templateIndex, templateSummary, templateTaxonomy} {
for _, name := range []string{templatePost, templateError, templateRedirect, templateIndex, templateSummary, templateTaxonomy, templateMenu} {
templates[name] = loadTemplate(name)
}
}

View File

@ -6,5 +6,10 @@
<meta http-equiv=x-ua-compatible content="IE=edge">
<link rel="stylesheet" href="{{ asset "css/style.scss" }}">
{{ template "title" . }}
<header>
<h1><a href="/" rel="home" title="{{ blog.Title }}">{{ blog.Title }}</a></h1>
{{ with blog.Description }}<p><i>{{ . }}</i></p>{{ end }}
{{ include "menu" . }}
</header>
{{ template "main" . }}
{{ end }}

11
templates/menu.gohtml Normal file
View File

@ -0,0 +1,11 @@
{{ define "menu" }}
<nav>
{{ with menu "main" }}
{{ $first := true }}
{{ range $i, $item := .Items }}
{{ if ne $first true }} &bull; {{ end }}<a
href="{{ $item.Link }}">{{ $item.Title }}</a>{{ $first = false }}
{{ end }}
{{ end }}
</nav>
{{ end }}