camp-homepage/gallery/themes/autophugo/layouts/partials/header.html
2023-02-05 13:58:44 +01:00

40 lines
1.9 KiB
HTML

<header id="header">
<h1>
<!-- Grab the base URL, pull out the path, then count directories -->
{{- $base_url_parsed := urls.Parse .Site.BaseURL -}}
{{- $base_dir := trim $base_url_parsed.Path "/" -}}
{{- $base_part_cnt := cond (ne $base_dir "") (len (split $base_dir "/" )) 0 -}}
<!-- Grab the current URL, separate it out -->
{{- $url_parsed := urls.Parse .Permalink -}}
{{- $trimmed_url := trim $url_parsed.Path "/" -}}
{{- $pre_url_parts := split $trimmed_url "/" -}}
{{- $pre_part_count := len $pre_url_parts -}}
<!-- Drop the part of the current URL that's the base URL -->
{{- $url_parts := last (sub $pre_part_count $base_part_cnt) $pre_url_parts -}}
{{- $part_count := len $url_parts -}}
<!-- Determine how much of the URL to use (sometimes last part is blank) -->
{{- $last_part := index $url_parts (sub $part_count 1) -}}
{{- $use_part_cnt := cond (eq (trim $last_part " ") "") (sub $part_count 1) $part_count -}}
<!-- Determine whether to use URL components or titles for breadcrumb -->
{{- $crumb_is_title := .Site.Params.breadcrumb_use_title | default false -}}
<!-- Build the breadcrumb - base URL link, path links for each dir, cur location text -->
<a href="{{ .Site.BaseURL }}"><strong>{{ .Site.Title }}</strong></a>
{{- if gt $use_part_cnt 0 -}}
{{- range $cur_ind, $element := first (sub $use_part_cnt 1) $url_parts -}}
{{- $path := string (delimit (first (add $cur_ind 1) $url_parts) "/") -}}
{{- $part := $element | humanize }}
/ <a href="{{ $.Site.BaseURL }}{{ $path }}"><strong>{{ cond $crumb_is_title ((($.Site.GetPage $path).Title) | default $part) $part }}</strong></a>
{{- end -}}
{{- $cur_part := (index $url_parts (sub $use_part_cnt 1)) | humanize }}
/ {{ cond $crumb_is_title (.Title | default $cur_part) $cur_part }}
{{- end }}
</h1>
{{ partial "navigation.html" . }}
</header>