Merge pull request #36 from lierdakil/use-index-pages

Use index pages + automatic navigation arrows
This commit is contained in:
Mathieu Cornic 2017-04-01 15:55:13 +02:00 committed by GitHub
commit 460f0365d1
7 changed files with 108 additions and 45 deletions

View file

@ -1,9 +1,6 @@
---
title: "Some Chapter title"
weight: 0
prev: /prev/path
next: /next/path
chapter: true
icon: "<b>X. </b>" # HTML code as prefix in the menu
---

View file

@ -1,8 +1,6 @@
---
title: "Some Title"
weight: 5
prev: /prev/path
next: /next/path
toc: true
---

View file

@ -0,0 +1,13 @@
{{ if .Content }}
{{ partial "header.html" . }}
{{ .Content }}
{{ 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,14 +1,54 @@
{{ if .Params.chapter }}
{{ $isChapter := .Params.chapter | default (eq .Kind "section")}}
{{ if $isChapter }}
</div> <!-- end chapter-->
{{ end }}
</div>
</div>
{{ if $.Site.Params.autoNav }}
{{ $.Scratch.Set "_sectionpages" (slice) }}
{{ if $.Site.Params.menu }}
{{ range $sname := $.Site.Params.menu }}
{{ $.Scratch.Add "_sectionpages" ($.Site.GetPage "section" $sname) }}
{{ end }}
{{ else }}
{{ range $sname, $spages := .Site.Sections }}
{{ $.Scratch.Add "_sectionpages" ($.Site.GetPage "section" $sname) }}
{{ end }}
{{ $.Scratch.Set "_sectionpages" (sort ($.Scratch.Get "_sectionpages") "Weight") }}
{{ end }}
{{ $.Scratch.Set "_allpages" (slice) }}
{{ range $.Scratch.Get "_sectionpages" }}
{{ if .Content }}
{{ $.Scratch.Add "_allpages" . }}
{{ end }}
{{ range index $.Site.Sections .Section }}
{{ $.Scratch.Add "_allpages" .Page }}
{{ end }}
{{ end }}
{{ end }}
<div id="navigation">
{{ $Site := .Site }}
{{ with .Params.prev }}<a class="nav nav-prev" href="{{ $Site.BaseURL }}{{ . }}"> <i class="fa fa-chevron-left"></i></a>{{ end }}
{{ with .Params.next }}<a class="nav nav-next" href="{{ $Site.BaseURL }}{{ . }}" style="margin-right: 0px;"><i class="fa fa-chevron-right"></i></a>{{ end }}
{{ if $.Site.Params.autoNav }}
{{ $allpages := $.Scratch.Get "_allpages" }}
{{ range $index, $element := $allpages }}
{{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>
{{ end }}
{{ end }}
{{ if not (isset $.Params "next") }}
{{ with index $allpages (add $index 1) }}
<a class="nav nav-next" href="{{ .URL }}" style="margin-right: 0px;"><i class="fa fa-chevron-right"></i></a>
{{ end }}
{{ end }}
{{ end }}
{{ end }}
{{ end }}
{{ with .Params.prev }}<a class="nav nav-prev" href="{{ . | relURL }}"> <i class="fa fa-chevron-left"></i></a>{{ end }}
{{ with .Params.next }}<a class="nav nav-next" href="{{ . | relURL }}" style="margin-right: 0px;"><i class="fa fa-chevron-right"></i></a>{{ end }}
</div>
</section>

View file

@ -22,6 +22,7 @@
{{ partial "style.html" . }}
</head>
<body class="" data-url="{{ .RelPermalink }}">
{{ $isChapter := .Params.chapter | default (eq .Kind "section")}}
{{ partial "menu.html" . }}
<section id="body">
<div id="overlay"></div>
@ -47,15 +48,20 @@
<i class="fa fa-bars"></i>
</a>
</span>
{{ if and (not .Params.chapter) (.Params.toc) }}
{{ 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 }}
{{ if ne $.Section "" }}
{{ $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 }}
@ -67,10 +73,10 @@
{{ end }}
</div>
{{ if .Params.chapter }}
{{ if $isChapter }}
<div id="chapter">
{{ end }}
<div id="body-inner">
{{ if not .Params.chapter }}
<div id="body-inner">
{{ if not $isChapter }}
<h1>{{.Title}}</h1>
{{ end }}

View file

@ -11,56 +11,65 @@
<div class="highlightable">
<ul class="topics">
{{ $page := . }}
{{ if .Site.Params.menu }}
{{ $.Scratch.Set "menuItems" (slice) }}
{{ range $i, $key := .Site.Params.menu }}
{{ if isset $page.Site.Sections $key }}
{{ $.Scratch.Add "menuItems" $key }}
{{ else }}
<li class="dd-item"><div class="notices warning"><p>
{{ printf "Unknown section '%s' found in site menu" $key }}
</p></div></li>
{{ if $.Site.Params.menu }}
{{ $.Scratch.Set "menuItems" $.Site.Params.menu }}
{{ else }}
{{ $.Scratch.Set "_pages" (slice) }}
{{ range $key, $value := .Site.Sections }}
{{ $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 }}
{{ else }}
{{ $.Scratch.Set "menuItems" .Site.Sections }}
{{ $.Scratch.Set "menuItems" (slice)}}
{{ range $key, $value := sort ($.Scratch.Get "_pages") "Weight" }}
{{ $.Scratch.Add "menuItems" $value.Section }}
{{ end }}
{{ end }}
{{ $menuItems := $.Scratch.Get "menuItems" }}
{{ range $i, $key := $menuItems }}
{{ if ne $key "" }}
{{ if not $.Site.Params.menu }}
{{ $.Scratch.Set "currentItem" (index $page.Site.Sections $i) }}
{{ else }}
{{ $.Scratch.Set "currentItem" (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 if gt $value.Len 0}}
{{ $.Scratch.Set "first" (index $value 0).Page }}
{{ if gt $value.Len 1 }}
{{ $.Scratch.Set "_value" (after 1 $value) }}
{{ else }}
{{ $.Scratch.Set "_value" nil }}
{{ end }}
{{ end }}
{{ end }}
{{ $value := $.Scratch.Get "currentItem" }}
{{ $first := (index $value 0).Page }}
{{ $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>
</a>
{{ if gt $value.Len 1}}
{{ if gt $value.Len 0}}
<ul>
{{ range $k, $p := $value }}
{{ if gt $k 0 }}
<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 }}
{{ end }}
</ul>
{{ end }}
</li>

View file

@ -8,7 +8,7 @@ description = "Documentation theme for Hugo, based on Grav Learn theme"
homepage = "https://matcornic.github.io/hugo-learn-doc/basics/what-is-this-hugo-theme/"
tags = ["documentation", "grav", "learn", "doc"]
features = ["documentation"]
min_version = 0.17
min_version = 0.19
[author]
name = "Mathieu Cornic"