这将是一个简单的问题,但我已经花了很多时间,我无法找到一个明确的答案。以下是我博客的当前状态:https://brucou.github.io/
在Projects中,我有以下目录结构:
Projects
Component combinators
Trees and forests
Circuitry在我的项目页面(/projects/)中,我希望用相应的permalinks显示相应子文件夹的列表,即Component combinators、Trees 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我的问题是:
Projects目录内容?或者基本上如何在标题上做if?内容?项目目录的吗?也就是说,我只想在“项目”页面中显示此内容:
Component combinators
Trees and forests发布于 2017-12-25 20:59:13
就这样解决了:
{{ 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中),如果没有,则显示页面。
https://stackoverflow.com/questions/47904764
复制相似问题