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

Option to order sections by date for index.html #697

Open
micw opened this issue Jun 17, 2024 · 2 comments
Open

Option to order sections by date for index.html #697

micw opened this issue Jun 17, 2024 · 2 comments
Milestone

Comments

@micw
Copy link

micw commented Jun 17, 2024

In index.html sections are default-ordered (https://gohugo.io/methods/site/regularpages/). Would be nice to have an option to change this order (e.g. by date ascending)

@JincanDeng
Copy link

Same problem. Any method to change the order?

@micw
Copy link
Author

micw commented Jul 18, 2024

Here's the way I do it (switchable vie site parameter):

diff --git a/layouts/index.html b/layouts/index.html
index 4b826a1..84a5caf 100644
--- a/layouts/index.html
+++ b/layouts/index.html
@@ -11,6 +11,12 @@
     {{ $section_name := . }}
     {{/* Create a variable with that section to use in multiple places. */}}
     {{ $section := where $.Site.RegularPages "Section" "in" $section_name }}
+
+    {{ if $.Site.Params.order_by_date | default false }}
+    {{ $section = $section.ByDate }}
+    {{ end }}
+
+
     {{ $section_count := len $section }}
     {{ if ge $section_count 1 }}
       <div class="pa3 pa4-ns w-100 w-70-ns center">

micw added a commit to micw/gohugo-theme-ananke that referenced this issue Jul 18, 2024
@davidsneighbour davidsneighbour added this to the unplanned milestone Sep 19, 2024
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

Successfully merging a pull request may close this issue.

3 participants