{{- define "breadcrumb" }}
{{- $breadcrumb := slice }}
{{- $page := .page }}
{{- $to := .to }}
{{- $breadcrumb = $breadcrumb | append $to }}
{{- $depth := int (partial "get-page-depth.hugo" (dict "page" $page)) }}
{{- range seq $depth }}
{{- $to = $to.Parent }}
{{- if $to }}
{{- $breadcrumb = $breadcrumb | append $to }}
{{- else }}
{{- break }}
{{- end }}
{{- end }}
{{- $len := len $breadcrumb -}}
{{- $breadcrumbReversed := slice }}
{{- range seq $len }}
{{- $breadcrumbReversed = $breadcrumbReversed | append (index $breadcrumb (sub $len .)) }}
{{- end }}
{{- $remaining := $len }}
{{- $depth := 0 }}
{{- range $i, $e := $breadcrumbReversed }}
{{- $to := $e }}
{{- $ispublished := gt (int (len $to.Permalink)) 0 }}
{{- $remaining = sub $remaining 1 }}
{{- if $ispublished }}
{{- $depth = add $depth 1 }}
{{- $title := $to.Title }}
{{- if eq .Kind "taxonomy" }}
{{- $title = i18n $to.Data.Plural }}
{{- if not $title }}
{{- $title = $to.Data.Plural }}
{{- end }}
{{- else if eq .Kind "term" }}
{{- $title = i18n $to.Data.Singular }}
{{- if not $title }}
{{- $title = $to.Data.Singular }}
{{- end }}
{{- $title = printf "%s %s %s" $title (default "::" .Site.Params.titleSeparator) $to.Title }}
{{- end }}
{{- if not $title }}
{{- $title = $to.Site.Title }}
{{- end }}
{{ if $remaining }}{{end}}{{ $title }}{{ if $remaining }}{{ end }}{{ if $remaining }} {{ default ">" .Site.Params.breadcrumbSeparator }} {{ end }}
{{- end }}
{{- end }}
{{- end }}