Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Page navigation does not work as intended when no page weights are used #36

Open
ruir6o opened this issue Mar 17, 2021 · 0 comments
Open

Comments

@ruir6o
Copy link

ruir6o commented Mar 17, 2021

Hi, I'm using version 0.9.7 of your theme and I'm not setting any weights in the pages I'm creating since I want to order them alphabetically. To do this I set the ordersectionsby = "title" in the [params] section of my config.toml.

With this configuration I've noticed the following behaviour:

  • The Home page has a link to the next page but not a link to the previous page. [expected]
  • All intermediate pages have a link to the previous page and a link to the next page. [expected]
  • The last page has a link to the previous page and a link to a next page (that is the same as the previous page). [not expected]

Furthermore, the sidebar has the pages sorted alphabetically by their title however the navigation links themselves are still sorted by weight (which means they are "randomly" sorted in my case as I'm not assigning weights to the pages).

I've managed to fix this second issue by applying the following diff, however I'm not familiar with the inner workings of Hugo enough to understand how I can fix the first issue mentioned (this is my first time using Hugo).

diff --git a/layouts/partials/pagination.html b/layouts/partials/pagination.html
index 104ea8a..c81daf6 100644
--- a/layouts/partials/pagination.html
+++ b/layouts/partials/pagination.html
@@ -1,6 +1,6 @@
 {{- $currentNode := . -}}
 <nav class="pagination">
-{{- template "pagination" dict "menu" .Site.Home "currentnode" $currentNode "menu_exclusion" .Site.Params.menu_exclusion -}}
+{{- template "pagination" dict "menu" .Site.Home "currentnode" $currentNode "menu_exclusion" .Site.Params.menu_exclusion "ordersectionsby" .Site.Params.ordersectionsby -}}
 {{- with ($.Scratch.Get "prevPage") -}}
 <a class="nav nav-prev" href="{{ .Permalink }}" title="{{ .Title }}"><i class="fas fa-arrow-left" aria-hidden="true"></i>&nbsp;Prev - {{ .Title }}</a>
 {{ end -}}
@@ -12,6 +12,7 @@
 {{- define "pagination" -}}
 {{- $currentNode := .currentnode -}}
 {{- $menu_exclusion := .menu_exclusion -}}
+{{- $order_sections_by := .ordersectionsby -}}
 
 {{- if hasPrefix $currentNode.Permalink .menu.Permalink -}}
   {{- $currentNode.Scratch.Set "NextPageOK" "OK" -}}
@@ -38,7 +39,13 @@
   {{- $currentNode.Scratch.Set "pages" (.menu.Pages | union .menu.Sections) -}}
 {{- end -}}
 {{- $pages := ($currentNode.Scratch.Get "pages") -}}
-{{- range $pages.ByWeight -}}
-  {{- template "pagination" dict "menu" . "currentnode" $currentNode "menu_exclusion" $menu_exclusion -}}
+{{- if eq $order_sections_by "title" -}}
+  {{- range $pages.ByTitle -}}
+    {{- template "pagination" dict "menu" . "currentnode" $currentNode "menu_exclusion" $menu_exclusion "ordersectionsby" $order_sections_by -}}
+  {{- end -}}
+{{- else -}}
+  {{- range $pages.ByWeight -}}
+    {{- template "pagination" dict "menu" . "currentnode" $currentNode "menu_exclusion" $menu_exclusion "ordersectionsby" $order_sections_by -}}
+  {{- end -}}
 {{- end -}}
 {{- end -}}

P.S: I haven't created a PR for this diff since I'm not familiar with how Hugo works. This was just what I inferred from looking at some files and thus might not be the best way to tackle this problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant