For a hierarchical documentation site (tree structure), I’m looking to create automated navigations. I have directories and a _index.md
page in each one.
On each page, I list child pages and siblings. In pseudo code, I have something like this.
A list of subpages in the content:
{{ with .Pages }}
{{ range . }}
...
and a list of siblings pages underneath
{{ with .Parent }}
{{ range .Pages }}
...
So far, so trivial and works perfectly.
Next, I add some related. But I don’t want a link in related that’s already in subpages or siblings. So I do something like this (here for siblings):
{{ $related := .Site.RegularPages.Related . }}
{{ $related = complement .Parent.Pages $related | first 5 }}
{{ with $related }}
{{ range . }}
Of course, I add conditions to display nothing if the list of related is null. I won’t elaborate here.
Now: the hard question (for me)! Knowing that all links in the body of the article are made with {{ relref }}
or {{ ref }}
, I’d like to:
- list all the links in the article and
- create a slice
Then I could make a complement
to remove them from all the links in the children, siblings or related sections. This way, the same link would never appear twice on the page.
I’m interested in any suggestions you may have for creating a collection from markdown content.
Subsidiary question. Is it possible to use absolute or relative links in pure Markdown to generalize the tool?
[About](/site/about/)
[About](about)
[About](https://mysite.com/site/about/)
Thanks for your feedback and advice