This context in nav

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

View File

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

View File

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

View File

@ -2,7 +2,7 @@
<div><b>service Level 1</b></div>
<ul>
{{#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}}
</ul>
</footer>

View File

@ -12,11 +12,12 @@
<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>
<li {{#if Active }}class="active"{{/if }}><a href="{{ GoTo }}" title="{{ This.Data.hoverText }}">{{ Navname }}</a>
{{#if SubSlice }}
<ul>
{{#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 }}
</ul
{{/if }}
@ -28,7 +29,7 @@
<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 {{#if Active }}class="active"{{/if }}><a href="{{ GoTo }}" title="{{ This.Data.hoverText }}">{{ Navname }}</a>
</li>
{{/each }}
</ul>
@ -38,8 +39,9 @@
</div>
</header>
<div id="breadcrumb">
{{#each NavActive }}
<a href="{{ GoTo }}">{{ Navname }}</a>
<a href="{{ GoTo }}" title="{{ This.Data.hoverText }}">{{ Navname }}</a>
{{/each}}
</div>

78
main.go
View File

@ -48,12 +48,15 @@ type GlobalConfig struct {
var globalConfig = new(GlobalConfig)
type ThisPathConfig struct {
Navname *string `yaml:"Navname"`
GoTo *string `yaml:"GoTo"`
Data interface{} `yaml:"Data"`
}
// PathConfig of subdir
type PathConfig struct {
This struct {
Navname *string `yaml:"Navname"`
GoTo *string `yaml:"GoTo"`
} `yaml:"This"`
This ThisPathConfig `yaml:"This"`
Template *string `yaml:"Template"`
@ -94,53 +97,6 @@ type PathConfigTree struct {
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)
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")
mergo.Merge(newConfig, conf)
// remove this
newConfig.This.GoTo = nil
newConfig.This.Navname = nil
newConfig.This = ThisPathConfig{}
} else {
log.Debug("reading config...")
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")
mergeConfig(newConfig, conf)
oldThis := newConfig.This
mergo.Merge(newConfig, conf)
newConfig.This = oldThis
log.Debug(spew.Sdump(newConfig))
}
@ -251,6 +209,10 @@ type navElement struct {
GoTo string
Active bool
Data interface{}
This ThisPathConfig
SubMap *map[string]*navElement
SubSlice *[]*navElement
}
@ -275,10 +237,13 @@ func buildNavigation(conf *PathConfigTree, curNavMap *map[string]*navElement, cu
subSlice := make([]*navElement, 0)
navEl := navElement{
Active: strings.HasPrefix(activeNav, elPath),
Data: el.Config.Data,
SubMap: &subMap,
SubSlice: &subSlice,
}
navEl.This = el.Config.This
if navEl.Active {
// add to navActive level navigation
currentLevel := strings.Count(activeNav, "/")
@ -365,7 +330,10 @@ func processContent(conf *PathConfigTree) {
}
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))
input = regex.ReplaceAll(input, []byte(""))