svg

Zola: Create Archive Page

zola

Aku ingin membuat halaman /archive yang berisi list semua artikel yang aku tulis. Semua artikel yang aku tulis aku taruh di direktori ./content dan halaman archive aku buat di ./content/pages/archive.md. Berikut ini strukturnya:

.
├── config.toml
├── content
│   ├── 2017-04-27-memperbaiki-touchpad-error-di-fedora.md
│   ├── 2017-05-07-mencoba-oh-my-zsh.md
│   ├── 2025-01-04-podman-postgresql-and-pgadmin.md
│   ├── 2025-01-04-shrink-disk-image.md
│   ├── 2025-01-05-aplikasi-desktop-baru-yang-menarik.md
│   ├── 2025-01-07-fix-k3s-dns-issue.md
│   ├── _index.md
│   └── pages
│       ├── about.md
│       ├── archive.md
│       ├── contact.md
│       ├── encrypt.md
│       └── _index.md
├── templates
│   ├── archive.html
│   └── index.html

isi dari ./content/pages/archive.md:

+++
title = "Archive"
path = "archive"
template = "archive.html"
+++

isi dari templates/archive.html

{% set blog_section = get_section(path="_index.md") %}
{% for year, posts in blog_section.pages | group_by(attribute="year") %}
<h2>{{ year }}</h2>
<ul>
    {% for post in posts %}
    <li><a href="{{ post.permalink }}">{{ post.title }}</a></li>
    {% endfor %}
</ul>
{% endfor %}

get_section() ini bisa digunakan untuk mengakses konten dari section lain. misalnya aku punya section blog di content/blog dan aku ingin membuat archivenya, aku bisa menggunakan get_section(path="blog/_index.md").

referensi: Access content from other sections