Can I get sections that match like a glob pattern?

I’m looking into setting up a more complex docs site and I think that I need to structure my content folder like this:

-- products/
--- product a/ 
---- [...]
---- latest/ <-- all latest content
-- products/
--- product b/ 
---- [...]
---- latest/ <-- all latest content

normally I set up a sidebar that would just grab all sections of "products’ and loop through a template to autogen my links, however in this case I actually need to grab products/**/latest as a set to feed that template. I’m sure this is possible, but a bit fuzzy on the best way to do it.

for context, the nav layout is below and works but we have that extra middle layer that I’d like to ignore.

<aside id="sidebar" class="transform translate-x-0 md:translate-x-0 fixed md:relative top-0 left-0 w-full md:w-64 h-full bg-gray-800 text-white shadow-md transition-transform duration-300 ease-in-out">
  <div class="p-6">
      <!-- Close Button for Mobile -->
      <button id="closeSidebar" class="md:hidden mb-4 focus:outline-none">
          <span class="text-xl">×</span>

      <!-- Sidebar Header -->
      <h2 class="text-xl font-semibold mb-4">Documentation</h2>

      {{if .IsHome}}
      <!-- Grab and display all content/products sub directories -->
      {{ $productSections := .Site.GetPage "section" "products" }}

      {{ template "directory" (dict "dir" $productSections.Sections "current" .RelPermalink "parent" .Parent "section" .CurrentSection "level" "1")  }}
      {{ template "directory" (dict "dir" .FirstSection.Sections "current" .RelPermalink "parent" .Parent "section" .CurrentSection "level" "1")  }}

{{ define "directory" }}
{{$currentpg := .}}
{{ range .dir }}
{{ if and (not .Params.hidden) (or (eq .BundleType "branch") ( ) }}
  <ul class="space-y-2">
          <a class="{{if eq $.level "1" }}font-bold{{else if eq $.level "2"}}pl-4{{else}}pl-8{{end}} {{ if eq $.current .RelPermalink }}text-blue-400{{else}}text-white{{end}}" href="{{ .RelPermalink }}" data-parent="{{.Parent.RelPermalink}}" data-section="{{.CurrentSection.RelPermalink}}">
              <span class="arrow">▶</span> 
              {{if .Title}}{{.Title}}{{else}}{{ path.BaseName . | humanize }}{{end}}
          {{ template "directory" (dict "dir" .Pages "current" $.current "parent" .Parent "section" $.section "level" "2") }}
{{ else }}
  {{ if and (not .Params.hidden) }}
  <ul class="space-y-2">
    <li class="{{if (eq $.section.Title .CurrentSection.Title) }}{{else}}closed-folder{{end}}">
      <a class="pl-8 {{ if eq $.current .RelPermalink }}text-blue-400{{else}}text-white{{end}}" href="{{ .RelPermalink }}">{{if .Title}}{{.Title}}{{else}}{{ path.BaseName . | humanize }}{{end}}</a>
{{ end }}
{{ end }}
{{ end }}

In the files for the “latest” directories, can you add front matter:

latest = true

And then do:

{{ $p := where site.Pages "Section" "products" }}
{{ $latestSectionPages := where $p "Params.latest" true }}

Then walk $latestSectionPages to build your list?

Or you use a taxonomy, then grab the pages for the term.

1 Like

The where function also has a like operator…

{{ $p := where site.Pages "Kind" "section" }}
{{ $p = where $p "Section" "products" }}
{{ $p = where $p "File.Path" "like" `latest` }}
1 Like