Add support for Hugo Table of Contents

Fixes #42
This commit is contained in:
budparr 2018-04-09 11:16:02 -04:00
parent 3f2fac220c
commit aa37d617a5
No known key found for this signature in database
GPG Key ID: 05AB7813F9C39728
4 changed files with 14 additions and 24 deletions

View File

@ -1,24 +1,6 @@
{{/* Get the current page's URL so we can compare it to the list below */}} {{- if .Params.toc -}}
{{ $currentPageUrl := .URL }} <div class="bg-light-gray mb-4 pa3 nested-list-reset nested-copy-line-height nested-links">
{{/* Get a list of this section's other pages. "RegularPages" excludes the list page */}} <p class="list b mb3">What's in this {{ humanize .Type }}</p>
{{ $currentSection := (where .Site.RegularPages "Section" .Section) }} {{ .TableOfContents }}
{{/* Get the number of entries of $currentSection and subtract 1 */}}
{{ $i := sub ($currentSection | len) 1 }}
{{/* So we can only show this menu if there are one or more other entries */}}
{{ if ge $i 1 }}
<div class="bg-light-gray pa3">
<ul>
<li class="list b mb3">{{/* Return the section name, make it readable (humanize) and if there are 2 or more entries, make the section name plural (pluralize). */}}
{{ $i }} More {{ if ge $i 2 }}{{ .Section | humanize | pluralize }}{{ else }}{{ .Section | humanize }}{{end}}
</li>
{{ range $currentSection }}
<li class="list f5 w-100 hover-bg-white nl1">
{{/* If the URL returned is the same as the current URL dim it so we know that that's the page we're on. NOTE: Should probably use a more accessible way of displaying this. */}}
<a href="{{ .URL }}" class="link ph2 pv2 db black{{ if eq $currentPageUrl .URL }} o-50{{end}}">
{{ .Title }}
</a>
</li>
{{ end }}
</ul>
</div> </div>
{{ end }} {{- end -}}

View File

@ -25,3 +25,7 @@
.pagination li.active a:visited { .pagination li.active a:visited {
background-color: #ddd; background-color: #ddd;
} }
#TableOfContents ul li {
margin-bottom: 1em;
}

View File

@ -1 +1,5 @@
/* Put your custom styles here and run `npm start` from the "src" directory on */ /* Put your custom styles here and run `npm start` from the "src" directory on */
#TableOfContents ul li {
margin-bottom: 1em;
}

File diff suppressed because one or more lines are too long