direct navlevel navigation
This commit is contained in:
parent
7f3b4ab8f9
commit
11113eece0
@ -53,4 +53,12 @@ footer {
|
||||
|
||||
.nav li.active>a {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
#langSelect a img {
|
||||
border: 2px solid grey;
|
||||
}
|
||||
|
||||
#langSelect a:hover img {
|
||||
border: 2px solid black;
|
||||
}
|
8
example/content/README.md
Normal file
8
example/content/README.md
Normal file
@ -0,0 +1,8 @@
|
||||
---
|
||||
Template: intro.html
|
||||
|
||||
---
|
||||
|
||||
# Willkommen
|
||||
|
||||
Bitte wählen Sie eine Sprache:
|
@ -1,6 +1,3 @@
|
||||
This:
|
||||
GoTo: "/de/main/home"
|
||||
|
||||
Index:
|
||||
InputFile: "README.md"
|
||||
OutputFile: "index.html"
|
||||
|
BIN
example/content/de.png
Normal file
BIN
example/content/de.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 247 B |
2
example/content/de/config.yml
Normal file
2
example/content/de/config.yml
Normal file
@ -0,0 +1,2 @@
|
||||
This:
|
||||
GoTo: main/home
|
BIN
example/content/en.png
Normal file
BIN
example/content/en.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.6 KiB |
2
example/content/en/config.yml
Normal file
2
example/content/en/config.yml
Normal file
@ -0,0 +1,2 @@
|
||||
This:
|
||||
GoTo: main/home
|
19
example/templates/intro.html
Normal file
19
example/templates/intro.html
Normal 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>
|
@ -1,19 +1,34 @@
|
||||
<header>
|
||||
<div id="logoDiv"><img src="../assets/img/logo.png"></div>
|
||||
<div id="mainNavDiv" class="nav">
|
||||
<div><b>main Level 1</b></div>
|
||||
<ul>
|
||||
{{#each NavMap.de.SubMap.main.SubSlice }}
|
||||
<li {{#if Active }}class="active"{{/if }}><a href="{{ GoTo }}">{{ Navname }}</a>
|
||||
{{#if SubSlice }}
|
||||
<ul>
|
||||
{{#each SubSlice }}
|
||||
<li {{#if Active }}class="active"{{/if }}><a href="{{ GoTo }}">{{ Navname }}</a></li>
|
||||
{{/each }}
|
||||
</ul
|
||||
{{/if }}
|
||||
</li>
|
||||
{{/each }}
|
||||
</ul>
|
||||
<table border="0" style="width: 100%">
|
||||
<tr>
|
||||
<td>
|
||||
<div><b>main Level 1 ...</b></div>
|
||||
<ul>
|
||||
{{#each NavActive.[0].SubMap.main.SubSlice }}
|
||||
<li {{#if Active }}class="active"{{/if }}><a href="{{ GoTo }}">{{ Navname }}</a>
|
||||
{{#if SubSlice }}
|
||||
<ul>
|
||||
{{#each SubSlice }}
|
||||
<li {{#if Active }}class="active"{{/if }}><a href="{{ GoTo }}">{{ Navname }}</a></li>
|
||||
{{/each }}
|
||||
</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>
|
||||
</header>
|
||||
|
@ -1,4 +1,6 @@
|
||||
<meta>
|
||||
<meta charset="UTF-8">
|
||||
|
||||
<title>{{ Meta.Title }}</title>
|
||||
<meta name="description" content="{{ Meta.Description }}" />
|
||||
<meta name="keywords" content="{{ Meta.Keywords }}" />
|
||||
|
39
main.go
39
main.go
@ -255,7 +255,7 @@ type navElement struct {
|
||||
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 {
|
||||
ignNav := el.Config.Path.IgnoreForNav
|
||||
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)
|
||||
}
|
||||
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
|
||||
}
|
||||
}
|
||||
@ -279,6 +279,15 @@ func buildNavigation(conf *PathConfigTree, curNavMap *map[string]*navElement, cu
|
||||
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
|
||||
if n != nil {
|
||||
navEl.Navname = *n
|
||||
@ -311,7 +320,7 @@ func buildNavigation(conf *PathConfigTree, curNavMap *map[string]*navElement, cu
|
||||
*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
|
||||
curNavPath := strings.TrimPrefix(conf.OutputPath, *outDir+"/")
|
||||
var navMap = make(map[string]*navElement)
|
||||
buildNavigation(contentConfig, &navMap, nil, curNavPath)
|
||||
curNavPath := strings.TrimPrefix(conf.OutputPath, *outDir)
|
||||
curNavPath = strings.TrimPrefix(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
|
||||
ctx := make(map[string]interface{})
|
||||
ctx["Meta"] = newConfig.Meta
|
||||
ctx["Data"] = newConfig.Data
|
||||
ctx["NavMap"] = navMap
|
||||
ctx["NavSlice"] = navSlice
|
||||
ctx["NavActive"] = navActive
|
||||
ctx["Body"] = string(html)
|
||||
|
||||
result, err := template.Exec(ctx)
|
||||
@ -440,16 +458,19 @@ func processContent(conf *PathConfigTree) {
|
||||
if find := globalConfig.Assets.FixTemplate.Find; find != "" {
|
||||
log.Debugf("fixing assets paths in '%s' for '%s'", templateFile, inFile)
|
||||
tmpPath := ""
|
||||
for i := len(strings.Split(curNavPath, "/")); i > 0; i-- {
|
||||
tmpPath += "../"
|
||||
if curNavPath != "" {
|
||||
for i := len(strings.Split(curNavPath, "/")); i > 0; i-- {
|
||||
tmpPath += "../"
|
||||
}
|
||||
}
|
||||
regex, err := regexp.Compile(find)
|
||||
if err != nil {
|
||||
log.Panicf("could not compile regexp '%s' for assets path: %s", find, err)
|
||||
}
|
||||
repl := globalConfig.Assets.FixTemplate.Replace
|
||||
repl = tmpPath + "/" + globalConfig.Assets.ToPath + "/" + repl
|
||||
repl = tmpPath + globalConfig.Assets.ToPath + "/" + repl
|
||||
repl = path.Clean(repl) + "/"
|
||||
log.Debugf("new assets paths: %s", repl)
|
||||
result = regex.ReplaceAllString(result, repl)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user