diff options
| author | Aditya Telange <21258296+adityatelange@users.noreply.github.com> | 2021-02-12 12:31:00 +0530 |
|---|---|---|
| committer | Aditya Telange <21258296+adityatelange@users.noreply.github.com> | 2021-02-12 13:13:33 +0530 |
| commit | 17d48ce9bb9be4f462963edfe40d56c412d32c2d (patch) | |
| tree | 65724069c4b7cb70beb60060fd21cd108f3db38d | |
| parent | a21094f4a046b7f2d9419d0f62d7643964ef8fce (diff) | |
add structured data for breadcrumb nav
https://developers.google.com/search/docs/data-types/breadcrumb
| -rw-r--r-- | layouts/partials/templates/schema_json.html | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/layouts/partials/templates/schema_json.html b/layouts/partials/templates/schema_json.html index 5cf407e..6e71082 100644 --- a/layouts/partials/templates/schema_json.html +++ b/layouts/partials/templates/schema_json.html @@ -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", @@ -75,4 +114,6 @@ } } </script> +{{ end }}{{/* .IsPage end */}} + {{ end }} |
