Skip to content

Commit

Permalink
improve breadcrumb schema generation
Browse files Browse the repository at this point in the history
  • Loading branch information
zeeZ committed Mar 29, 2024
1 parent dad94ab commit 5cac2b5
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions layouts/partials/templates/schema_json.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
{{- $url := replace .Parent.Permalink ( printf "%s" site.Home.Permalink) "" }}
{{- $lang_url := strings.TrimPrefix ( printf "%s/" .Lang) $url }}
{{- $bc_list := (split $lang_url "/")}}
{{- $position := 0 }}

{{- $scratch := newScratch }}
<script type="application/ld+json">
Expand All @@ -34,21 +35,22 @@
{{- $bc_pg := site.GetPage ($scratch.Get "path") -}}
{{- if (and ($bc_pg) (gt (len . ) 0))}}
{{- $position = add 1 $position }}
{{- if (and $index)}}, {{end }}
{
"@type": "ListItem",
"position": {{ add 1 $index }},
"position": {{ $position }},
"name": {{ $bc_pg.Name }},
"item": {{ $bc_pg.Permalink | safeHTML }}
}
{{- end }}
{{- end }}
{{- /* self-page addition */ -}}
{{- if (ge (len $bc_list) 2) }}, {{end }}
{{- if (gt (len $bc_list) 0) }}, {{end }}
{
"@type": "ListItem",
"position": {{len $bc_list}},
"position": {{ add 1 $position }},
"name": {{ .Name }},
"item": {{ .Permalink | safeHTML }}
}
Expand Down

0 comments on commit 5cac2b5

Please sign in to comment.