breadcrumbs.html 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <!--
  2. <div role="navigation" aria-label="breadcrumbs navigation">
  3. {{ $url := replace .Permalink ( printf "%s" .Site.BaseURL) "" }}
  4. {{ $.Scratch.Add "path" .Site.BaseURL }}
  5. {{ $.Scratch.Add "currentURL" .URL }}
  6. {{ $pageNotFound := (eq (replace $.Site.BaseURL .Site.BaseURL "404.html") .URL) }}
  7. <ul class="breadcrumbs">
  8. {{ range $index, $element := split $url "/" }}
  9. {{ $.Scratch.Add "path" $element }}
  10. {{ $.Scratch.Add "path" "/" }}
  11. &lt;!&ndash; Check if the current list item is the last one &ndash;&gt;
  12. {{ $isLast := eq ($.Scratch.Get "path") $.Permalink }}
  13. {{ if ne $element "" }}
  14. {{ if and (not $isLast) (not $pageNotFound) }}
  15. <li><a href='{{ $.Scratch.Get "path" }}'>{{ title ( replace . "-" " ") }}</a> &rsaquo;</li>
  16. {{ else if $pageNotFound }}
  17. <li>404</li>
  18. {{ else }}
  19. <li>{{ $.Title }}</li>
  20. {{ end }}
  21. {{ end }}
  22. {{ end }}
  23. </ul>
  24. </div>
  25. -->
  26. <ul class="breadcrumbs">
  27. {{ template "breadcrumb" dict "currentPage" .Page "id" .UniqueID }}
  28. </ul>
  29. <!-- templates -->
  30. {{ define "breadcrumb" }}
  31. {{ if .currentPage.Parent }}
  32. {{ template "breadcrumb" dict "currentPage" .currentPage.Parent }}
  33. {{ end }}
  34. {{ $title := cond (eq .currentPage.RelPermalink "/docs/" ) "Docs" (title .currentPage.Title) }}
  35. {{ if (ne .currentPage.Parent .IsHome) }}
  36. <li>
  37. {{ if eq .id .currentPage.UniqueID }}
  38. {{ $title }}
  39. {{ else }}
  40. <a href="{{ .currentPage.RelPermalink }}">{{ $title }}</a>
  41. {{ end }}
  42. </li>
  43. {{ end }}
  44. {{ end }}