Fixes, see description

* fix menu ordering when mixing chapters and non-chapters
* allow for `chapter` type override in `_index` pages
* fix breadcrumbs
* fix some crashes with empty categories
* use page context in list.html (to avoid setting uniqueid in scratch)
* use UniqueID instead of relative links for page identification
This commit is contained in:
Nikolay Yakimov 2017-03-27 22:57:49 +03:00
parent eac49beee1
commit 7aa1e70638
No known key found for this signature in database
GPG key ID: 8E9303568F9B9650
4 changed files with 36 additions and 27 deletions

View file

@ -1,10 +1,13 @@
{{ partial "header.html" . }}
{{ if .Content }}
{{ partial "header.html" . }}
{{ .Content }}
{{ else }}
{{ with (index (index .Site.Sections .Section) 0) }}
{{ .Page.Content }}
{{ $.Scratch.Set "uniqueId" .Page.UniqueID }}
{{ end }}
{{ end }}
{{ partial "footer.html" . }}
{{ else }}
{{ with (index (index .Site.Sections .Section) 0) }}
{{ with .Page }}
{{ partial "header.html" . }}
{{ .Content }}
{{ partial "footer.html" . }}
{{ end }}
{{ end }}
{{ end }}

View file

@ -1,5 +1,5 @@
{{ $isChapter := or (eq .Kind "section") (.Params.chapter)}}
{{ $isChapter := .Params.chapter | default (eq .Kind "section")}}
{{ if $isChapter }}
</div> <!-- end chapter-->
{{ end }}
@ -33,8 +33,7 @@
{{ if $.Site.Params.autoNav }}
{{ $allpages := $.Scratch.Get "_allpages" }}
{{ range $index, $element := $allpages }}
{{ $uniqueid := ($.Scratch.Get "uniqueId" | default $.UniqueID ) }}
{{if eq $element.UniqueID $uniqueid }}
{{if eq $element.UniqueID $.UniqueID }}
{{ if not (isset $.Params "prev") }}
{{ with index $allpages (sub $index 1) }}
<a class="nav nav-prev" href="{{ .URL }}"> <i class="fa fa-chevron-left"></i></a>

View file

@ -22,7 +22,7 @@
{{ partial "style.html" . }}
</head>
<body class="" data-url="{{ .RelPermalink }}">
{{ $isChapter := or (eq .Kind "section") (.Params.chapter)}}
{{ $isChapter := .Params.chapter | default (eq .Kind "section")}}
{{ partial "menu.html" . }}
<section id="body">
<div id="overlay"></div>
@ -51,14 +51,17 @@
{{ if and (not $isChapter) (.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>
{{ end }}
{{ $section := index .Site.Sections .Section }}
{{ $sectionPage := $.Site.GetPage "section" $.Section }}
{{ if $sectionPage.Content }}
{{ $first := $.Site.GetPage "section" $.Section }}
{{ if ne $first.UniqueID $.UniqueID }}
<a href="{{ $first.RelPermalink }}" itemprop="url"><span itemprop="title">{{ $first.Title }}</span></a> <i class="fa fa-angle-right"></i>
{{ end }}
{{ else if gt $section.Len 0 }}
{{ $first := (index $section 0).Page }}
{{ if ne $first.UniqueID $.UniqueID }}
<a href="{{ $first.RelPermalink }}" itemprop="url"><span itemprop="title">{{ $first.Title }}</span></a> <i class="fa fa-angle-right"></i>
{{ end }}
{{ end }}
{{ with .Title }}<span itemprop="title"> {{ . }}</span>{{ end }}

View file

@ -11,13 +11,17 @@
<div class="highlightable">
<ul class="topics">
{{ $page := . }}
{{ if $.Site.Params.menu }}
{{ $.Scratch.Set "menuItems" $.Site.Params.menu }}
{{ else }}
{{ $.Scratch.Set "_pages" (slice) }}
{{ range $key, $value := .Site.Sections }}
{{ $.Scratch.Add "_pages" ($.Site.GetPage "section" $key) }}
{{ $sectionPage := $.Site.GetPage "section" $key }}
{{ if $sectionPage.Content }}
{{ $.Scratch.Add "_pages" $sectionPage }}
{{ else if gt $value.Len 0 }}
{{ $.Scratch.Add "_pages" (index $value 0).Page }}
{{ end }}
{{ end }}
{{ $.Scratch.Set "menuItems" (slice)}}
{{ range $key, $value := sort ($.Scratch.Get "_pages") "Weight" }}
@ -28,12 +32,12 @@
{{ range $i, $key := $menuItems }}
{{ if ne $key "" }}
{{ $value := (index $page.Site.Sections $key) }}
{{ $value := (index $.Site.Sections $key) }}
{{ $.Scratch.Set "_value" $value }}
{{ with $index := $.Site.GetPage "section" $key }}
{{ if .Content }}
{{ $.Scratch.Set "first" $index }}
{{ else }}
{{ else if gt $value.Len 0}}
{{ $.Scratch.Set "first" (index $value 0).Page }}
{{ if gt $value.Len 1 }}
{{ $.Scratch.Set "_value" (after 1 $value) }}
@ -45,14 +49,14 @@
{{ $first := $.Scratch.Get "first" }}
{{ $value := $.Scratch.Get "_value" }}
<li class="dd-item {{ if eq $page.RelPermalink $first.RelPermalink }}active{{ end }} {{if in $page.RelPermalink $first.RelPermalink }}parent{{ end }}" data-nav-id="{{ $first.RelPermalink }}">
<li class="dd-item {{ if eq $.UniqueID $first.UniqueID }}active{{ end }} {{if eq $.Section $first.Section }}parent{{ end }}" data-nav-id="{{ $first.RelPermalink }}">
<a href="{{ $first.RelPermalink }}">
<span>
{{ if isset $first.Params "icon" }}
{{ printf $first.Params.icon | safeHTML }}
{{ end }}
{{ $first.Title }}
{{ if $page.Site.Params.showVisitedLinks}}
{{ if $.Site.Params.showVisitedLinks}}
<i class="fa fa-check read-icon"></i>
{{ end }}
</span>
@ -60,9 +64,9 @@
{{ if gt $value.Len 0}}
<ul>
{{ range $k, $p := $value }}
<li class="dd-item {{ if eq $page.RelPermalink $p.Page.RelPermalink }}active{{ end }}" data-nav-id="{{ $p.Page.RelPermalink }}">
<li class="dd-item {{ if eq $.UniqueID $p.Page.UniqueID }}active{{ end }}" data-nav-id="{{ $p.Page.RelPermalink }}">
<a href="{{ $p.Page.RelPermalink }}">
<span>{{ $p.Page.Title }} {{ if $page.Site.Params.showVisitedLinks}} <i class="fa fa-check read-icon"> {{ end }} </i></span>
<span>{{ $p.Page.Title }} {{ if $.Site.Params.showVisitedLinks}} <i class="fa fa-check read-icon"> {{ end }} </i></span>
</a>
</li>
{{ end }}