direct navlevel navigation
This commit is contained in:
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)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user