mirror of
https://github.com/McShelby/hugo-theme-relearn.git
synced 2024-11-23 15:57:57 +00:00
theme: revised schema.org breadcrumb navigation #329
to get rid of HTML validation errors and remove descending positions
This commit is contained in:
parent
c0f1f7fa60
commit
583dd0c97a
1 changed files with 25 additions and 11 deletions
|
@ -91,8 +91,7 @@
|
||||||
{{- $showBreadcrumb := (and (not .Params.disableBreadcrumb) (not .Site.Params.disableBreadcrumb)) }}
|
{{- $showBreadcrumb := (and (not .Params.disableBreadcrumb) (not .Site.Params.disableBreadcrumb)) }}
|
||||||
{{- if $showBreadcrumb }}
|
{{- if $showBreadcrumb }}
|
||||||
<ol class="links" itemscope itemtype="http://schema.org/BreadcrumbList">
|
<ol class="links" itemscope itemtype="http://schema.org/BreadcrumbList">
|
||||||
<meta itemprop="itemListOrder" content="Descending">
|
{{- template "breadcrumb" dict "page" . }}
|
||||||
{{- template "breadcrumb" dict "page" . "depth" 0 }}
|
|
||||||
</ol>
|
</ol>
|
||||||
{{- else }}
|
{{- else }}
|
||||||
<span class="links">
|
<span class="links">
|
||||||
|
@ -111,16 +110,31 @@
|
||||||
{{- partial "tags.html" . }}
|
{{- partial "tags.html" . }}
|
||||||
</div>
|
</div>
|
||||||
{{- define "breadcrumb" }}
|
{{- define "breadcrumb" }}
|
||||||
{{- $parent := .page.Parent }}
|
{{- $breadcrumb := slice }}
|
||||||
{{- $ispublished := gt (int (len .page.Permalink)) 0 }}
|
{{- $page := .page }}
|
||||||
{{- $depth := .depth }}
|
{{- $breadcrumb = $breadcrumb | append $page }}
|
||||||
|
{{- range seq (len .page.Site.Home.Pages) }}
|
||||||
|
{{- $page = $page.Parent }}
|
||||||
|
{{- if $page }}
|
||||||
|
{{- $breadcrumb = $breadcrumb | append $page }}
|
||||||
|
{{- 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 }}
|
||||||
|
{{- $page := $e }}
|
||||||
|
{{- $ispublished := gt (int (len $page.Permalink)) 0 }}
|
||||||
|
{{- $remaining = sub $remaining 1 }}
|
||||||
{{- if $ispublished }}
|
{{- if $ispublished }}
|
||||||
{{- $depth = add $depth 1 }}
|
{{- $depth = add $depth 1 }}
|
||||||
|
<li itemscope itemtype="https://schema.org/ListItem" itemprop="itemListElement">{{ if $remaining }}<a itemprop="item" href="{{ $page.RelPermalink }}">{{end}}<span itemprop="name">{{ if $page.Title }}{{ $page.Title }}{{ else }}{{ $page.Site.Title }}{{ end }}</span>{{ if $remaining }}</a>{{ end }}<meta itemprop="position" content="{{ $depth }}"></li>{{ if $remaining }} > {{ end }}
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- if $parent }}
|
|
||||||
{{- template "breadcrumb" dict "page" $parent "depth" $depth }}
|
|
||||||
{{- end }}
|
|
||||||
{{- if $ispublished }}
|
|
||||||
<li itemscope itemtype="https://schema.org/ListItem" itemprop="itemListElement"><meta itemprop="position" content="{{ $depth }}"><a itemprop="item" href="{{ .page.RelPermalink }}"{{if not .depth}} aria-disabled="true"{{end}}><span itemprop="name">{{if .page.Title}}{{ .page.Title }}{{else}}{{ .page.Site.Title }}{{end}}</span></a>{{ if .depth }} > {{ end }}</li>
|
|
||||||
{{- end }}
|
{{- end }}
|
||||||
{{- end }}
|
{{- end }}
|
Loading…
Reference in a new issue