Hello,
I created a page at /archive
that displays all the posts categorized by date, as shown in the picture below. The titles were generated using GPT.
The code that generated this:
{{ define "main" }}
<div class="card">
<h2>Archive</h2>
{{ range (site.RegularPages.GroupByPublishDate "2006") }}
{{ if ne .Key "0001" }}
{{- $year := replace .Key "0001" "" }}
<h3>{{ $year }}</h3>
<ul class="archive-list">
{{- range .Pages.GroupByDate "January" }}
{{ range .Pages }}
<li>
{{ .Date.Format "02 Jan" }} - <a href="{{ .Permalink }}">{{ .Title | markdownify }}</a>
</li>
{{ end }}
{{ end }}
</ul>
{{ end }}
{{ end }}
</div>
{{ end }}
The problem is that I can’t implement pagination because it’s not supported for this type of content. It would be better if, when I access /archive
, only the year and the number of posts in that year are displayed, and then, upon clicking, a list of just the posts from that year appears.
I think that would require me to have links formatted like /archive/2023/
and /archive/2024/
, but I’m not sure if that can be achieved with my current structure.
+ content
+ archive
- index.org
#+title: Posts Archive
#+type: archive
#+summary: This page contains an archive of all posts.
+ posts
+ first-post
- index.org
+ second-post
- index.org
...
+ layout
+ archive
- list.html <- the code shown above generating the archive page
My hugo.toml
uses this configuration, but these only apply to posts and taxonomies:
# Permalinks
[permalinks]
posts = "posts/:year/:month/:slug"
year = "/posts/:slug/"
month = "/posts/:slug/"
# Taxonomies
[taxonomies]
year = "year"
month = "month"
tag = "tags"
category = "categories"
I’m not sure if what I’m trying to do is possible, but if it is, I would appreciate any tips on how to go about it. I want to have a page at /archive
that shows the years, and when I click on a year, it displays the posts for that year. It would be great if pagination could be added only for the pages that show the list of posts.
Any suggestion appreciated.