--- draft: false title: "Adding Series and Navigation links to Hugo page" aliases: ["Adding Series and Navigation links to Hugo page"] series: ["blogging-with-quartz"] series_order: 3 date: "2023-03-07" author: "Nick Dumas" cover: "" description: "Extending Quartz's single.html to link between posts." showFullContent: false keywords: - quartz - webdev - hugo tags: - quartz - webdev - hugo --- ## What am I Doing? As I write more posts, I realize I'm writing groups of posts that are narratively linked, to speak. The best example is this series, Blogging with Quartz. There are others, but I'm still working on a system for cross-linking between posts. More on that later. I also realized that there's simply no way to view anything but the most recent N posts on the index page. I've forgotten what the current value of N is but that's neither here nor there. Users can't navigate free. The closest they can get is walking the tag graph and hoping that gets them somewhere. ## Why does it work? Quartz is great, looks awesome and uses Hugo which means its super configurable. The templates are powerful and very polarizing. ## Why doesn't it work? Quart's layout seems to be build around organize discovery of notes through hand crafted landing pages. For the blog, I'm not interested in that. I want users to be able to page through my posts backwards and forwards chronologically like any actual blog site. Quartz has tags but it lacks a way of saying "These posts aren't chronologically adjacent but they form a sequence". It looks like most tools call this a "series" of posts, so that's what I went with. ## Making it happen ### Chronological Adjacency Hugo helps us here by providing [page variables](https://gohugo.io/variables/page/) specifically for this: `Next` and `NextInSection`. This partial ends up being really straightforward. It's also got a style, `pagination` that I'm going to leverage. ```html {{partial "prev-next.html" .}} ``` Just a few `if` statements and calling `.Permalink` to get a URL. I chose to use the `*InSection` variants because I probably will be introducing more content types over time and I may as well fix this beforehand. Below is `layouts/partials/prev-next.html` ```html {{ if or .NextInSection .PrevInSection }} {{ end }} ``` There's also a small block of custom CSS, necessary to reset some padding and make the links flow horizontally with a bit of a margin to keep them legible. Shown is a portion of `asset/styles/custom.scss`. ```css ... nav.pagination { border: 1px solid black; ol { padding-inline-start: 0px; } li { margin: .25em; display: inline-block; } } ... ``` ![[Resources/attachments/prev-next-links-example.png]] Pretty snazzy, right? ### Planning for the Future Tags are cool, but they don't tell a story. My ambition vastly outstrips my talent and so no project I undertake will ever fit in a single post. To that end, I put this together. I definitely got this from somewhere, but I can't remember where now. Sorry. Another very simple invocation. ```html {title="layouts/_default/single.html"} {{partial "series-header.html" . }} ``` This generates a short list linking to all the other posts in a given series. ```html {title="layouts/partials/series-header.html"} {{- if .Params.series -}} {{- with index (.GetTerms "series") 0 -}}