page-header.html 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. {{ $geekdocRepo := default (default false .Site.Params.geekdocRepo) .Page.Params.geekdocRepo }}
  2. {{ $geekdocEditPath := default (default false .Site.Params.geekdocEditPath) .Page.Params.geekdocEditPath }}
  3. {{ if .File }}
  4. {{ $.Scratch.Set "geekdocFilePath" (default (strings.TrimPrefix hugo.WorkingDir .File.Filename) .Page.Params.geekdocFilePath) }}
  5. {{ else }}
  6. {{ $.Scratch.Set "geekdocFilePath" false }}
  7. {{ end }}
  8. {{ define "breadcrumb" }}
  9. {{ $parent := .page.Parent }}
  10. {{ if $parent }}
  11. {{ $name := (partial "utils/title" $parent) }}
  12. {{ $position := (sub .position 1) }}
  13. {{ $value := (printf "<li itemprop='itemListElement' itemscope itemtype='https://schema.org/ListItem'><a itemscope itemtype='https://schema.org/WebPage' itemprop='item' itemid='%s' href='%s'><span itemprop='name'>%s</span></a><meta itemprop='position' content='%d' /></li><li> / </li>%s" $parent.RelPermalink $parent.RelPermalink $name $position .value) }}
  14. {{ template "breadcrumb" dict "page" $parent "value" $value "position" $position }}
  15. {{ else }}
  16. {{ .value | safeHTML }}
  17. {{ end }}
  18. {{ end }}
  19. {{ $showBreadcrumb := (and (default true .Page.Params.geekdocBreadcrumb) (default true .Site.Params.geekdocBreadcrumb)) }}
  20. {{ $showEdit := (and ($.Scratch.Get "geekdocFilePath") $geekdocRepo $geekdocEditPath) }}
  21. <div
  22. class="gdoc-page__header flex flex-wrap
  23. {{ if $showBreadcrumb }}
  24. justify-between
  25. {{ else }}
  26. justify-end
  27. {{ end }}
  28. {{ if not $showEdit }}hidden-mobile{{ end }}
  29. {{ if (and (not $showBreadcrumb) (not $showEdit)) }}hidden{{ end }}"
  30. itemprop="breadcrumb"
  31. >
  32. {{ if $showBreadcrumb }}
  33. <div>
  34. <svg class="gdoc-icon gdoc_path hidden-mobile"><use xlink:href="#gdoc_path"></use></svg>
  35. <ol class="breadcrumb" itemscope itemtype="https://schema.org/BreadcrumbList">
  36. {{ $position := sub (len (split .RelPermalink "/")) 1 }}
  37. {{ $name := (partial "utils/title" .) }}
  38. {{ $value := (printf "<li itemprop='itemListElement' itemscope itemtype='https://schema.org/ListItem'><span itemprop='name'>%s</span><meta itemprop='position' content='%d' /></li>" $name $position ) }}
  39. {{ template "breadcrumb" dict "page" . "value" $value "position" $position }}
  40. </ol>
  41. </div>
  42. {{ end }}
  43. {{ if $showEdit }}
  44. <div>
  45. <span class="editpage">
  46. <svg class="gdoc-icon gdoc_code"><use xlink:href="#gdoc_code"></use></svg>
  47. <a
  48. href="{{ $geekdocRepo }}/{{ path.Join $geekdocEditPath ($.Scratch.Get "geekdocFilePath") }}"
  49. >
  50. {{ i18n "edit_page" }}
  51. </a>
  52. </span>
  53. </div>
  54. {{ end }}
  55. </div>