Added menu generation from defenition on content.md files, selectable using params .createFromSiteMenusMain on toml file. (#5)

Fixes #2
This commit is contained in:
Xipas 2016-10-02 17:12:30 +01:00 committed by Mathieu Cornic
parent de8584e890
commit 64012f31af
2 changed files with 66 additions and 9 deletions

View file

@ -48,16 +48,32 @@
{{ if and (not .Params.chapter) (.Params.toc) }}
<span id="toc-menu"><a href=""><i class="fa fa-list-alt"></i></a></span>
{{ end }}
{{ $type := .Type }}
{{ $relLink := .RelPermalink }}
{{ range $name , $value := .Site.Sections }}
{{ if eq $name $type }}
{{ $first := (index $value 0).Page }}
{{ if ne $first.RelPermalink $relLink }}
<a href="{{ $first.RelPermalink }}" itemprop="url"><span itemprop="title">{{ $first.Title }}</span></a> <i class="fa fa-angle-right"></i>
{{ if $page.Site.Params.createFromSiteMenusMain}}
{{ $type := .Params.menu.main.parent }}
{{ $relLink := .RelPermalink }}
{{ range $name , $value := .Site.Menus.main }}
{{ if eq $value.Identifier $type }}
{{ if ne $relLink $value.URL }}
<a href="{{ $value.URL }}" itemprop="url"><span itemprop="title"> <b>{{ $value.Name }}</b></span></a> <i class="fa fa-angle-right"></i>
{{ end }}
{{ end }}
{{ end }}
{{ end }}
{{ end }}
{{else}} <!-- use current method as default-->
{{ $type := .Type }}
{{ $relLink := .RelPermalink }}
{{ range $name , $value := .Site.Sections }}
{{ if eq $name $type }}
{{ $first := (index $value 0).Page }}
{{ if ne $first.RelPermalink $relLink }}
<a href="{{ $first.RelPermalink }}" itemprop="url"><span itemprop="title">{{ $first.Title }}</span></a> <i class="fa fa-angle-right"></i>
{{ end }}
{{ end }}
{{ end }}
{{end}}
{{ with .Title }}<span itemprop="title"> {{ . }}</span>{{ end }}
</div>
{{ if .Params.toc }}

View file

@ -16,6 +16,42 @@
<div class="highlightable">
<ul class="topics">
{{ $page := . }}
{{ if $page.Site.Params.createFromSiteMenusMain}}
{{ range .Site.Menus.main }}
<li class="dd-item {{ if eq $page.RelPermalink .URL }}active{{ end }} {{if in $page.RelPermalink .URL }}parent{{ end }}" data-nav-id="{{.URL}}">
<a href="{{.URL}}">
<span>{{ .Pre }} {{ .Name }} {{ if $page.Site.Params.showVisitedLinks}} <i class="fa fa-check read-icon"> {{ end }} </i> </span>
</a>
{{ if .HasChildren }}
<ul>
{{ range $lvl2 := .Children}}
<li class="dd-item {{ if eq $page.RelPermalink $lvl2.URL }}active{{ end }}" data-nav-id="{{$lvl2.URL}}">
<a href="{{$lvl2.URL}}">
<span> {{ $lvl2.Pre }} {{ $lvl2.Name }} {{ if $page.Site.Params.showVisitedLinks}} <i class="fa fa-check read-icon"></i> {{ end }} </span>
</a>
{{ if $lvl2.HasChildren }}
<!-- if children has children 3rd level -->
<ul>
{{ range $lvl3 := $lvl2.Children}}
<li class="dd-item {{ if eq $page.RelPermalink $lvl3.URL }}active{{ end }}" data-nav-id="{{$lvl3.URL}}">
<a href="{{$lvl3.URL}}">
<span>{{ $lvl3.Pre }} {{ $lvl3.Name }} {{ if $page.Site.Params.showVisitedLinks}} <i class="fa fa-check read-icon"></i> {{ end }} </span>
</a>
</li>
{{ end }}
</ul>
{{ end }}
</li>
{{ end }}
</ul>
{{ end }}
</li>
{{ end }}
{{else}}
<!-- Use default method, create menu from folder structure -->
{{ range $key , $value := .Site.Sections }}
{{ if ne $key "" }}
{{ $first := (index $value 0).Page }}
@ -48,6 +84,11 @@
</li>
{{ end }}
{{ end }}
{{ end }}
</ul>
<hr>
{{ if .Site.Params.showVisitedLinks}}