Previous tag and next tag

I’m in the midst of turning each of my tag[*] pages into a kind of portal[**]. I’d like to have links to “previous tag” and “next tag” on each tag page so people can easily step through these portals. I’ve read the docs and this discussion group and so far haven’t been able to figure out how to do this other than manually specifying something like this in each tag’s front matter:

previoustag: /tag/gohugo/
nexttag: /tag/unicode/

Is it possible to automate this? I’m guessing it is, but since I barely know Go Templating I haven’t been able to figure it out. I’d appreciate any tips!

[*] On my site “tag” is a taxonomy (or is it a taxonomyTerm‽)

[**] These portals are not yet public, but you can get an idea of what I want to do by looking at https://www.ii.com/tag/qutebrowser/

So I have not tested this, but I wonder if .NextInSection and .PrevInSection will work for tags, since they’re still pages.

That would be cool.

I did not test it, either. But a single taxonomy page is:

.IsPage: false
.IsNode: true
.Kind:   taxonomy

Thanks for your thoughts @zwbetz and @Grob. Unfortunately .NextInSection and .PrevInSection do not work for tags so I’m doing it with this in my baseof.html:

{{ if .Params.prevOverride }}
  <a href="{{ .Params.prevOverride }}">Previous</a>
{{ else if .PrevInSection }}
  <a href="{{ .PrevInSection.Permalink }}">Previous</a>
{{ else }}
  <span style="visibility: hidden;">Previous</a>
{{ end }}

And similar Go template code for Next.

For each tag that I want in my tag Previous/Next stack, I create an _index.adoc that looks like this:

---
title: qutebrowser
prevOverride: /tag/vim/
nextOverride: /tag/gohugo/
---

The above is my /content/tag/qutebrowser/_index.adoc.

I need to manually do this for each tag so if anyone figures out a way to do this without creating all these tag/foo directories and tag/foo/_index.adoc files, please post!

Thank you!

PS - If you’re wondering why I use visibility: hidden; in the final else, it’s because I need it for the layout of my pages to look right.

PPS - If anyone else wants to do something like this, you can use _index.md rather than _index.adoc if you prefer Markdown to AsciiDoc.

1 Like