Building out a documentation site that also has blogging and podcasting functionality (which are just copies of each other, tbh).
I’m working on the documentation side of it now and I’m having a bit of a problem ranging through subdirectories.
Content:
/Content
|- _index.md // home page
|
|- blog/
| └-- post-one/
| |- index.md
| └- asset.jpg
|
|- documentation/
| |- _index.md
| |- subject/
| |- _index.md
| └- specific-article/
| |- index.md
| └- asset.jpg
|
└- podcast/
On the documentation side, I have the intitial level page set up perfectly: Range through the subject sub-directories and pull their index pages for “categories”, and below that range all of the content pages of everything below itself. Easy enough.
Here’s how I achieved that:
{{ if eq .Section "answers" }}
<h2 class="text-2xl text-gray-700 mt-7 mb-7">Answers by Topic</h2>
<section class="w-full flex flex-wrap flex-row">
{{ range .Data.Pages }}
{{ if .IsSection }}
<a href="{{ .Permalink }}" class="flex flex-row items-center bg-gray-200 shadow m-2 py-5 px-7 rounded-xl cursor-pointer hover:bg-white transition-all duration-200 hover:shadow-lg">
<svg xmlns="http://www.w3.org/2000/svg" class="h-6 w-6 mr-2 inline" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z" />
</svg>
{{ .Title }}
</a>
{{ end }}
{{ end }}
</section>
<h2 class="text-2xl text-gray-700 mt-14">Browse All Answers</h2>
<section class="text-gray-600 body-font">
<div class="container px-5 py-8 mx-auto">
<div class="flex flex-wrap -mx-4 -my-8">
{{ range .Site.RegularPages }}
{{ .Render "summary" }}
{{ end }}
</div>
</div>
</section>
{{ end }}
My problem is when I’m in a subdirectory.
When I’m sitting at my documentation root this is perfect. But when I’m down side a specific /subject
directory I want to only list the pages inside that subject.
I don’t knwo if I need to create an entirely seperate template (hope not!), or if I can modify mine up there to include some kind of conditional or extra range?
Links
- The page that works as intended
- The broken page
- The Repo (Note: You can also see my actual directory structure here)
I hope my question makes sense! Let me know if I need to clarify anything. Any suggestions appreciated.