Skip to content

Commit

Permalink
add structured data for breadcrumb nav
Browse files Browse the repository at this point in the history
  • Loading branch information
adityatelange committed Feb 12, 2021
1 parent a21094f commit 17d48ce
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion layouts/partials/templates/schema_json.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,46 @@
]
}
</script>
{{- else if .IsPage }}
{{- else if (or .IsPage .IsSection) }}
{{/* BreadcrumbList */}}
{{- $url := replace .Parent.Permalink ( printf "%s" .Site.BaseURL) "" }}
{{- $lang_url := replace $url ( printf "%s" .Lang) "" }}
{{- $bc_list := (split $lang_url "/")}}

{{- $scratch := newScratch }}
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "BreadcrumbList",
"itemListElement": [
{{- range $index, $element := $bc_list }}

{{- $scratch.Add "path" (printf "%s/" $element ) | safeJS }}
{{- $bc_pg := $.Site.GetPage ($scratch.Get "path") -}}

{{- if (and ($bc_pg) (gt (len . ) 0))}}
{{- if (and $index)}}, {{end }}
{
"@type": "ListItem",
"position": {{ add 1 $index }},
"name": {{ $bc_pg.Name }},
"item": {{ $bc_pg.Permalink | safeHTML }}
}
{{- end }}

{{- end }}
{{- /* self-page addition */ -}}
{{- if $bc_list }}, {{end }}
{
"@type": "ListItem",
"position": {{len $bc_list}},
"name": {{ .Name }},
"item": {{ .Permalink | safeHTML }}
}
]
}
</script>
{{- if .IsPage }}
<script type="application/ld+json">
{
"@context": "https://schema.org",
Expand Down Expand Up @@ -75,4 +114,6 @@
}
}
</script>
{{ end }}{{/* .IsPage end */}}

{{ end }}

0 comments on commit 17d48ce

Please sign in to comment.