雨果中按类别列出所有页面

我在雨果中有结构:


content

├── 1.md

├── a

│   ├── 2.md

│   └── 3.md

└── b

    └── 4.md

我想要菜单列表如下:


1

一个

2

3

b

4

我现在正在使用


<ul>

    {{ range .Site.RegularPages }}

        <li>

            <a href="{{ .Permalink }}">{{ .Name }}</a>

        </li>

    {{ end }}

</ul>

这给了我:


1

2

3

4


浮云间
浏览 126回答 2
2回答

largeQ

layouts/partials/walk.html:<ul>&nbsp; {{ range .Pages.ByTitle }}&nbsp; &nbsp; <li>&nbsp; &nbsp; &nbsp; <a href="{{ .RelPermalink }}">{{ .Title }}</a>&nbsp; &nbsp; &nbsp; {{ if .Pages }}&nbsp; &nbsp; &nbsp; &nbsp; {{ partial "walk.html" . }}&nbsp; &nbsp; &nbsp; {{ end }}&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; </li>&nbsp; {{ end }}</ul>content/section/_index.md:---title: Section Name---layouts/index.html{{ partial "walk.html" }}

一只名叫tom的猫

最后,为了格式化数据,您仍在使用HTML,因此嵌套列表的规则仍然适用,例如:<ul>&nbsp; &nbsp; {{ range .OuterList }}&nbsp; &nbsp; &nbsp; &nbsp; <li>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <a href="#">{{ .OuterListItem }}</a>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {{if gt (len .OuterListItem.InnerItems) 0}}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <ul>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{{ range .OuterListItem.InnerItems }}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <li> {{ .InnerItem }} </li>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{{ end }}&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; </ul>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; {{ end }}&nbsp; &nbsp; &nbsp; &nbsp; </li>&nbsp; &nbsp; {{ end }}</ul>
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go