Feature: Add next and previous page links (#747)

* Rewrite prev-next with enw lang. selector
* Make sure next page stays on right side
* Align icon styles
This commit is contained in:
Alex Shpak
2025-07-31 23:18:41 +02:00
committed by GitHub
parent 92579b2c72
commit 9181135505
8 changed files with 67 additions and 4 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
<h2 class="book-brand">
<a class="flex align-center" href="{{ cond (not .Site.Home.File) .Sites.Default.Home.RelPermalink .Site.Home.RelPermalink }}">
{{- with .Site.Params.BookLogo -}}
<img src="{{ . | relURL }}" alt="Logo" class="book-icon" />
<img src="{{ . | relURL }}" alt="Logo" />
{{- end -}}
<span>{{ .Site.Title }}</span>
</a>
+2
View File
@@ -21,6 +21,8 @@
</div>
{{ partial "docs/prev-next" . }}
{{ $script := resources.Get "clipboard.js" | resources.Minify }}
{{ with $script.Content }}
<script>{{ . | safeJS }}</script>
+2 -2
View File
@@ -16,7 +16,7 @@
<label for="languages" class="flex">
<a role="button" class="flex flex-auto">
<img src="{{ "svg/translate.svg" | relURL }}" class="book-icon" alt="Languages" />
{{ $.Site.Language.LanguageName }}
<span>{{ $.Site.Language.LanguageName }}</span>
</a>
</label>
@@ -24,7 +24,7 @@
{{ range .Site.Languages }}{{ with index $translations .Lang }}
<li>
<a href="{{ cond hugo.IsMultihost .Permalink .RelPermalink }}">
{{ .Language.LanguageName }}
<span>{{ .Language.LanguageName }}</span>
</a>
</li>
{{ end }}{{ end }}
@@ -0,0 +1,14 @@
{{ $scratch := newScratch }}
{{ template "recurse" (dict "Scratch" $scratch "Sections" .) }}
{{ define "recurse" }}
{{ range .Sections }}
{{ if and .Content (not .Params.BookHidden) }}
{{ $.Scratch.Add "BookPages" (slice .) }}
{{ end }}
{{ if .IsSection }}
{{ template "recurse" (dict "Scratch" $.Scratch "Sections" .Pages) }}
{{ end }}
{{ end }}
{{ end }}
{{ return $scratch.Get "BookPages" }}
+31
View File
@@ -0,0 +1,31 @@
{{ $bookSection := default "docs" .Site.Params.BookSection }}
{{ if eq $bookSection "*" }}
{{ $bookSection = "/" }}{{/* Backward compatibility */}}
{{ end }}
{{ with .Site.GetPage $bookSection }}
{{ $pages := partialCached "docs/prev-next-cache" .Pages }}
{{ $prev := $pages.Next $ }}
{{ $next := $pages.Prev $ }}
{{- if or $prev $next }}
<div class="flex flex-wrap justify-between">
<span>
{{ with $prev }}
<a href="{{ .RelPermalink }}" class="flex align-center book-icon">
<img src="{{ "svg/backward.svg" | relURL }}" class="book-icon" alt="Previous" title="{{ partial "docs/title" . }}" />
<span>{{ partial "docs/title" . }}</span>
</a>
{{ end }}
</span>
<span>
{{ with $next }}
<a href="{{ .RelPermalink }}" class="flex align-center book-icon">
<span>{{ partial "docs/title" . }}</span>
<img src="{{ "svg/forward.svg" | relURL }}" class="book-icon" alt="Next" title="{{ partial "docs/title" . }}" />
</a>
{{ end }}
</span>
</div>
{{ end -}}
{{ end }}