This context in nav

This commit is contained in:
Sebastian Frank
2019-02-13 19:50:26 +01:00
parent 26418217ac
commit 2bcef447b9
6 changed files with 38 additions and 62 deletions

View File

@@ -1,2 +1,5 @@
This: This:
Navname: HOME Navname: HOME
Data:
hoverText: Hover Text

View File

@@ -1,2 +1,5 @@
This: This:
GoTo: adresse/ GoTo: adresse/
Data:
hoverText: weiterer Text

View File

@@ -2,7 +2,7 @@
<div><b>service Level 1</b></div> <div><b>service Level 1</b></div>
<ul> <ul>
{{#each NavMap.de.SubMap.service.SubSlice }} {{#each NavMap.de.SubMap.service.SubSlice }}
<li {{#if Active }}class="active"{{/if }}><a href="{{ GoTo }}">{{ Navname }}</a></li> <li {{#if Active }}class="active"{{/if }}><a href="{{ GoTo }}" title="{{ This.Data.hoverText }}">{{ Navname }}</a></li>
{{/each}} {{/each}}
</ul> </ul>
</footer> </footer>

View File

@@ -12,11 +12,12 @@
<div><b>main Level 1 ...</b></div> <div><b>main Level 1 ...</b></div>
<ul> <ul>
{{#each NavActive.[0].SubMap.main.SubSlice }} {{#each NavActive.[0].SubMap.main.SubSlice }}
<li {{#if Active }}class="active"{{/if }}><a href="{{ GoTo }}">{{ Navname }}</a> <li {{#if Active }}class="active"{{/if }}><a href="{{ GoTo }}" title="{{ This.Data.hoverText }}">{{ Navname }}</a>
{{#if SubSlice }} {{#if SubSlice }}
<ul> <ul>
{{#each SubSlice }} {{#each SubSlice }}
<li {{#if Active }}class="active"{{/if }}><a href="{{ GoTo }}">{{ Navname }}</a></li> <li {{#if Active }}class="active"{{/if }}><a href="{{ GoTo }}" title="{{ This.Data.hoverText }}">{{ Navname }}</a>
</li>
{{/each }} {{/each }}
</ul </ul
{{/if }} {{/if }}
@@ -28,7 +29,7 @@
<div><b>main/service Level 2</b></div> <div><b>main/service Level 2</b></div>
<ul> <ul>
{{#each NavActive.[2].SubSlice }} {{#each NavActive.[2].SubSlice }}
<li {{#if Active }}class="active"{{/if }}><a href="{{ GoTo }}">{{ Navname }}</a> <li {{#if Active }}class="active"{{/if }}><a href="{{ GoTo }}" title="{{ This.Data.hoverText }}">{{ Navname }}</a>
</li> </li>
{{/each }} {{/each }}
</ul> </ul>
@@ -38,8 +39,9 @@
</div> </div>
</header> </header>
<div id="breadcrumb"> <div id="breadcrumb">
{{#each NavActive }} {{#each NavActive }}
<a href="{{ GoTo }}">{{ Navname }}</a> <a href="{{ GoTo }}" title="{{ This.Data.hoverText }}">{{ Navname }}</a>
{{/each}} {{/each}}
</div> </div>

78
main.go
View File

@@ -48,12 +48,15 @@ type GlobalConfig struct {
var globalConfig = new(GlobalConfig) var globalConfig = new(GlobalConfig)
type ThisPathConfig struct {
Navname *string `yaml:"Navname"`
GoTo *string `yaml:"GoTo"`
Data interface{} `yaml:"Data"`
}
// PathConfig of subdir // PathConfig of subdir
type PathConfig struct { type PathConfig struct {
This struct { This ThisPathConfig `yaml:"This"`
Navname *string `yaml:"Navname"`
GoTo *string `yaml:"GoTo"`
} `yaml:"This"`
Template *string `yaml:"Template"` Template *string `yaml:"Template"`
@@ -94,53 +97,6 @@ type PathConfigTree struct {
Sub []*PathConfigTree Sub []*PathConfigTree
} }
func mergeConfig(mergeInto *PathConfig, mergeFrom *PathConfig) {
// navname, goto are individual, so no merging here
if mergeInto.Template == nil || *mergeInto.Template == "" { // always require a template
mergeInto.Template = mergeFrom.Template
}
if mergeInto.Index.InputFile == nil {
mergeInto.Index.InputFile = mergeFrom.Index.InputFile
}
if mergeInto.Index.InputFile == nil {
mergeInto.Index.InputFile = mergeFrom.Index.InputFile
}
if mergeInto.Index.OutputFile == nil {
mergeInto.Index.OutputFile = mergeFrom.Index.OutputFile
}
if mergeInto.Meta.Title == nil {
mergeInto.Meta.Title = mergeFrom.Meta.Title
}
if mergeInto.Meta.Description == nil {
mergeInto.Meta.Description = mergeFrom.Meta.Description
}
if mergeInto.Meta.Keywords == nil {
mergeInto.Meta.Keywords = mergeFrom.Meta.Keywords
}
if mergeInto.Path.IgnoreForNav == nil {
mergeInto.Path.IgnoreForNav = mergeFrom.Path.IgnoreForNav
}
if mergeInto.Path.Strip == nil {
mergeInto.Path.Strip = mergeFrom.Path.Strip
}
if mergeInto.Filename.Strip == nil {
mergeInto.Filename.Strip = mergeFrom.Filename.Strip
}
if mergeInto.Filename.Ignore == nil {
mergeInto.Filename.Ignore = mergeFrom.Filename.Ignore
}
if mergeInto.Filename.OutputExtension == nil {
mergeInto.Filename.OutputExtension = mergeFrom.Filename.OutputExtension
}
}
var contentConfig = new(PathConfigTree) var contentConfig = new(PathConfigTree)
func readContentDir(inBase string, outBase string, dir string, conf *PathConfig, tree *PathConfigTree) { func readContentDir(inBase string, outBase string, dir string, conf *PathConfig, tree *PathConfigTree) {
@@ -166,8 +122,7 @@ func readContentDir(inBase string, outBase string, dir string, conf *PathConfig,
log.Debug("no config.yml found in this directory, using upper configs") log.Debug("no config.yml found in this directory, using upper configs")
mergo.Merge(newConfig, conf) mergo.Merge(newConfig, conf)
// remove this // remove this
newConfig.This.GoTo = nil newConfig.This = ThisPathConfig{}
newConfig.This.Navname = nil
} else { } else {
log.Debug("reading config...") log.Debug("reading config...")
data, err := ioutil.ReadFile(configFile) data, err := ioutil.ReadFile(configFile)
@@ -180,7 +135,10 @@ func readContentDir(inBase string, outBase string, dir string, conf *PathConfig,
} }
log.Debug("merging config with upper config") log.Debug("merging config with upper config")
mergeConfig(newConfig, conf) oldThis := newConfig.This
mergo.Merge(newConfig, conf)
newConfig.This = oldThis
log.Debug(spew.Sdump(newConfig)) log.Debug(spew.Sdump(newConfig))
} }
@@ -251,6 +209,10 @@ type navElement struct {
GoTo string GoTo string
Active bool Active bool
Data interface{}
This ThisPathConfig
SubMap *map[string]*navElement SubMap *map[string]*navElement
SubSlice *[]*navElement SubSlice *[]*navElement
} }
@@ -275,10 +237,13 @@ func buildNavigation(conf *PathConfigTree, curNavMap *map[string]*navElement, cu
subSlice := make([]*navElement, 0) subSlice := make([]*navElement, 0)
navEl := navElement{ navEl := navElement{
Active: strings.HasPrefix(activeNav, elPath), Active: strings.HasPrefix(activeNav, elPath),
Data: el.Config.Data,
SubMap: &subMap, SubMap: &subMap,
SubSlice: &subSlice, SubSlice: &subSlice,
} }
navEl.This = el.Config.This
if navEl.Active { if navEl.Active {
// add to navActive level navigation // add to navActive level navigation
currentLevel := strings.Count(activeNav, "/") currentLevel := strings.Count(activeNav, "/")
@@ -365,7 +330,10 @@ func processContent(conf *PathConfigTree) {
} }
log.Debug("merging config with upper config") log.Debug("merging config with upper config")
mergeConfig(newConfig, conf.Config) oldThis := newConfig.This
mergo.Merge(newConfig, conf.Config)
newConfig.This = oldThis
log.Debug(spew.Sdump(newConfig)) log.Debug(spew.Sdump(newConfig))
input = regex.ReplaceAll(input, []byte("")) input = regex.ReplaceAll(input, []byte(""))