diff --git a/example/assets/css/main.css b/example/assets/css/main.css
index 3dab812..b3f563a 100644
--- a/example/assets/css/main.css
+++ b/example/assets/css/main.css
@@ -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;
}
\ No newline at end of file
diff --git a/example/content/README.md b/example/content/README.md
new file mode 100644
index 0000000..95a9d52
--- /dev/null
+++ b/example/content/README.md
@@ -0,0 +1,8 @@
+---
+Template: intro.html
+
+---
+
+# Willkommen
+
+Bitte wählen Sie eine Sprache:
diff --git a/example/content/config.yml b/example/content/config.yml
index 7db9a63..0294211 100644
--- a/example/content/config.yml
+++ b/example/content/config.yml
@@ -1,6 +1,3 @@
-This:
- GoTo: "/de/main/home"
-
Index:
InputFile: "README.md"
OutputFile: "index.html"
diff --git a/example/content/de.png b/example/content/de.png
new file mode 100644
index 0000000..eea2e58
Binary files /dev/null and b/example/content/de.png differ
diff --git a/example/content/de/config.yml b/example/content/de/config.yml
new file mode 100644
index 0000000..4360ebc
--- /dev/null
+++ b/example/content/de/config.yml
@@ -0,0 +1,2 @@
+This:
+ GoTo: main/home
\ No newline at end of file
diff --git a/example/content/en.png b/example/content/en.png
new file mode 100644
index 0000000..f1e0e12
Binary files /dev/null and b/example/content/en.png differ
diff --git a/example/content/en/config.yml b/example/content/en/config.yml
new file mode 100644
index 0000000..4360ebc
--- /dev/null
+++ b/example/content/en/config.yml
@@ -0,0 +1,2 @@
+This:
+ GoTo: main/home
\ No newline at end of file
diff --git a/example/templates/intro.html b/example/templates/intro.html
new file mode 100644
index 0000000..20c54ff
--- /dev/null
+++ b/example/templates/intro.html
@@ -0,0 +1,19 @@
+
+ {{> meta.html }}
+
+
+
+
+ {{{ Body }}}
+
+
+ {{#each NavSlice }}
+
+ {{/each }}
+
+
+
+
+
\ No newline at end of file
diff --git a/example/templates/partials/header.html b/example/templates/partials/header.html
index f314431..6cb4c05 100644
--- a/example/templates/partials/header.html
+++ b/example/templates/partials/header.html
@@ -1,19 +1,34 @@
-
main Level 1
-
- {{#each NavMap.de.SubMap.main.SubSlice }}
- - {{ Navname }}
- {{#if SubSlice }}
-
- {{/each }}
-
+
+
+
+ main Level 1 ...
+
+ {{#each NavActive.[0].SubMap.main.SubSlice }}
+ - {{ Navname }}
+ {{#if SubSlice }}
+
+ {{/each }}
+
+ |
+
+ main/service Level 2
+
+ {{#each NavActive.[2].SubSlice }}
+ - {{ Navname }}
+
+ {{/each }}
+
+ |
+
+
diff --git a/example/templates/partials/meta.html b/example/templates/partials/meta.html
index bb3a998..5db3917 100644
--- a/example/templates/partials/meta.html
+++ b/example/templates/partials/meta.html
@@ -1,4 +1,6 @@
+
+
{{ Meta.Title }}
diff --git a/main.go b/main.go
index 846c5bb..9f726a5 100644
--- a/main.go
+++ b/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)
}