direct navlevel navigation

This commit is contained in:
Sebastian Frank 2019-02-13 15:44:16 +01:00
parent 7f3b4ab8f9
commit 11113eece0
Signed by: apairon
GPG Key ID: 7270D06DDA7FE8C3
11 changed files with 100 additions and 26 deletions

View File

@ -53,4 +53,12 @@ footer {
.nav li.active>a { .nav li.active>a {
font-weight: bold; font-weight: bold;
}
#langSelect a img {
border: 2px solid grey;
}
#langSelect a:hover img {
border: 2px solid black;
} }

View File

@ -0,0 +1,8 @@
---
Template: intro.html
---
# Willkommen
Bitte wählen Sie eine Sprache:

View File

@ -1,6 +1,3 @@
This:
GoTo: "/de/main/home"
Index: Index:
InputFile: "README.md" InputFile: "README.md"
OutputFile: "index.html" OutputFile: "index.html"

BIN
example/content/de.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 247 B

View File

@ -0,0 +1,2 @@
This:
GoTo: main/home

BIN
example/content/en.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

View File

@ -0,0 +1,2 @@
This:
GoTo: main/home

View File

@ -0,0 +1,19 @@
<html>
{{> meta.html }}
<body>
<header>
<div id="logoDiv"><img src="../assets/img/logo.png"></div>
</header>
<div id="content">
{{{ Body }}}
<div id="langSelect">
{{#each NavSlice }}
<a href="{{ GoTo }}"><img src="{{ Navname }}.png" alt="{{ Navname }}" style="height: 100px;"></a>
{{/each }}
</div>
</div>
</body>
</html>

View File

@ -1,19 +1,34 @@
<header> <header>
<div id="logoDiv"><img src="../assets/img/logo.png"></div> <div id="logoDiv"><img src="../assets/img/logo.png"></div>
<div id="mainNavDiv" class="nav"> <div id="mainNavDiv" class="nav">
<div><b>main Level 1</b></div> <table border="0" style="width: 100%">
<ul> <tr>
{{#each NavMap.de.SubMap.main.SubSlice }} <td>
<li {{#if Active }}class="active"{{/if }}><a href="{{ GoTo }}">{{ Navname }}</a> <div><b>main Level 1 ...</b></div>
{{#if SubSlice }} <ul>
<ul> {{#each NavActive.[0].SubMap.main.SubSlice }}
{{#each SubSlice }} <li {{#if Active }}class="active"{{/if }}><a href="{{ GoTo }}">{{ Navname }}</a>
<li {{#if Active }}class="active"{{/if }}><a href="{{ GoTo }}">{{ Navname }}</a></li> {{#if SubSlice }}
{{/each }} <ul>
</ul {{#each SubSlice }}
{{/if }} <li {{#if Active }}class="active"{{/if }}><a href="{{ GoTo }}">{{ Navname }}</a></li>
</li> {{/each }}
{{/each }} </ul
</ul> {{/if }}
</li>
{{/each }}
</ul>
</td>
<td>
<div><b>main/service Level 2</b></div>
<ul>
{{#each NavActive.[2].SubSlice }}
<li {{#if Active }}class="active"{{/if }}><a href="{{ GoTo }}">{{ Navname }}</a>
</li>
{{/each }}
</ul>
</td>
</tr>
</table>
</div> </div>
</header> </header>

View File

@ -1,4 +1,6 @@
<meta> <meta>
<meta charset="UTF-8">
<title>{{ Meta.Title }}</title> <title>{{ Meta.Title }}</title>
<meta name="description" content="{{ Meta.Description }}" /> <meta name="description" content="{{ Meta.Description }}" />
<meta name="keywords" content="{{ Meta.Keywords }}" /> <meta name="keywords" content="{{ Meta.Keywords }}" />

39
main.go
View File

@ -255,7 +255,7 @@ type navElement struct {
SubSlice *[]*navElement SubSlice *[]*navElement
} }
func buildNavigation(conf *PathConfigTree, curNavMap *map[string]*navElement, curNavSlice *[]*navElement, activeNav string) { func buildNavigation(conf *PathConfigTree, curNavMap *map[string]*navElement, curNavSlice *[]*navElement, navActive *[]*navElement, activeNav string) {
for _, el := range conf.Sub { for _, el := range conf.Sub {
ignNav := el.Config.Path.IgnoreForNav ignNav := el.Config.Path.IgnoreForNav
if ignNav != nil && *ignNav != "" { if ignNav != nil && *ignNav != "" {
@ -264,7 +264,7 @@ func buildNavigation(conf *PathConfigTree, curNavMap *map[string]*navElement, cu
log.Panicf("could not compile IngoreForNav regexp '%s' in '%s': %s", *ignNav, el.InputPath, err) log.Panicf("could not compile IngoreForNav regexp '%s' in '%s': %s", *ignNav, el.InputPath, err)
} }
if regex.MatchString(path.Base(el.InputPath)) { if regex.MatchString(path.Base(el.InputPath)) {
log.Noticef("ignoring input directory '%s' in navigation", el.InputPath) log.Debugf("ignoring input directory '%s' in navigation", el.InputPath)
continue continue
} }
} }
@ -279,6 +279,15 @@ func buildNavigation(conf *PathConfigTree, curNavMap *map[string]*navElement, cu
SubSlice: &subSlice, SubSlice: &subSlice,
} }
if navEl.Active {
// add to navActive level navigation
currentLevel := strings.Count(activeNav, "/")
if len(*navActive) <= currentLevel {
// not registered
*navActive = append(*navActive, &navEl)
}
}
n := el.Config.This.Navname n := el.Config.This.Navname
if n != nil { if n != nil {
navEl.Navname = *n navEl.Navname = *n
@ -311,7 +320,7 @@ func buildNavigation(conf *PathConfigTree, curNavMap *map[string]*navElement, cu
*curNavSlice = append(*curNavSlice, &navEl) *curNavSlice = append(*curNavSlice, &navEl)
} }
buildNavigation(el, &subMap, &subSlice, activeNav) buildNavigation(el, &subMap, &subSlice, navActive, activeNav)
} }
} }
@ -421,15 +430,24 @@ func processContent(conf *PathConfigTree) {
} }
// build navigation // build navigation
curNavPath := strings.TrimPrefix(conf.OutputPath, *outDir+"/") curNavPath := strings.TrimPrefix(conf.OutputPath, *outDir)
var navMap = make(map[string]*navElement) curNavPath = strings.TrimPrefix(curNavPath, "/")
buildNavigation(contentConfig, &navMap, nil, curNavPath) curNavPath = path.Clean(curNavPath)
if curNavPath == "." {
curNavPath = ""
}
navMap := make(map[string]*navElement)
navSlice := make([]*navElement, 0)
navActive := make([]*navElement, 0)
buildNavigation(contentConfig, &navMap, &navSlice, &navActive, curNavPath)
// read yaml header as data for template // read yaml header as data for template
ctx := make(map[string]interface{}) ctx := make(map[string]interface{})
ctx["Meta"] = newConfig.Meta ctx["Meta"] = newConfig.Meta
ctx["Data"] = newConfig.Data ctx["Data"] = newConfig.Data
ctx["NavMap"] = navMap ctx["NavMap"] = navMap
ctx["NavSlice"] = navSlice
ctx["NavActive"] = navActive
ctx["Body"] = string(html) ctx["Body"] = string(html)
result, err := template.Exec(ctx) result, err := template.Exec(ctx)
@ -440,16 +458,19 @@ func processContent(conf *PathConfigTree) {
if find := globalConfig.Assets.FixTemplate.Find; find != "" { if find := globalConfig.Assets.FixTemplate.Find; find != "" {
log.Debugf("fixing assets paths in '%s' for '%s'", templateFile, inFile) log.Debugf("fixing assets paths in '%s' for '%s'", templateFile, inFile)
tmpPath := "" tmpPath := ""
for i := len(strings.Split(curNavPath, "/")); i > 0; i-- { if curNavPath != "" {
tmpPath += "../" for i := len(strings.Split(curNavPath, "/")); i > 0; i-- {
tmpPath += "../"
}
} }
regex, err := regexp.Compile(find) regex, err := regexp.Compile(find)
if err != nil { if err != nil {
log.Panicf("could not compile regexp '%s' for assets path: %s", find, err) log.Panicf("could not compile regexp '%s' for assets path: %s", find, err)
} }
repl := globalConfig.Assets.FixTemplate.Replace repl := globalConfig.Assets.FixTemplate.Replace
repl = tmpPath + "/" + globalConfig.Assets.ToPath + "/" + repl repl = tmpPath + globalConfig.Assets.ToPath + "/" + repl
repl = path.Clean(repl) + "/" repl = path.Clean(repl) + "/"
log.Debugf("new assets paths: %s", repl)
result = regex.ReplaceAllString(result, repl) result = regex.ReplaceAllString(result, repl)
} }