Hugo:如何在部分页面中显示子部分列表

Hugo : how to display in section page a list of subsections

这将是一个简单的问题,但我已经花了很多时间,找不到确定的答案。这是我博客的当前状态:https://brucou.github.io/

Projects中,我的目录结构如下:

Projects
  Component combinators
  Trees and forests
  Circuitry

在我的项目页面(/projects/)中,我想显示一个对应sub-folders的列表,即Component combinatorsTrees and forests等,与对应的永久链接。

我在 /layouts/projects/list.html

中有此代码
<ul>
  {{ template "section-tree-nav" .Site.Home }}
</ul>
{{ define "section-tree-nav" }}
  {{ range .Sections}}
    <li>{{ .Title }}
        <ul>
            {{ range .Pages }}
            <li><a href="{{ .RelPermalink}}">{{ .Title }}</a></li>
            {{ end }}
            <ul>
                {{ template "section-tree-nav" . }}
            </ul>
        </ul>
    </li>
  {{ end }}
{{ end }}

目前此代码显示在项目页面中,目录树,例如:

Posts
  Reactive programming : a component-based approach
  A componentization model for cyclejs
  Componentization against complexity
  User interfaces as reactive systems
Projects
  Component combinators

我的问题是:

也就是说,我只想在项目页面中显示这个:

  Component combinators
  Trees and forests

这样解决了:

{{ partial "header" . }}

<article>
    <header>
        {{ partial "title" . }}
        {{ with .Content }}{{.}}{{ end }}
    </header>

    {{ if (eq $.Parent.Title "Projects") }}
      <ul class="no-bullet">
          {{ range .Paginator.Pages }}
          {{ partial "li" . }}
          {{ end }}
      </ul>
      {{ partial "paginator" . }}
    {{ else }}
      {{ range (where .Site.Pages "Section" "projects") }}
        <ul class="no-bullet">
            {{ range .Sections }}
            <li>
                <span><time datetime="{{.Date}}">{{ .Date.Format .Site.Params.DateFmt }}</time></span>
                <a href="{{ .Permalink }}">{{ .Title }}</a>
            </li>
            {{ end }}
        </ul>
      {{ end }}
    {{ end }}

</article>
{{ partial "footer" . }}


{{/* keep the / right next to the parenthesis */}}
{{/* printf "%#v" $.CurrentSection.Title */}}
{{/* printf "%#v" (eq $.Parent.Title "Projects") */}}

基本上,我们在层次结构的级别上进行分支。如果在顶层,那么我们显示目录(存储在 .Sections 中),如果不是,我们显示页面。