Minor codestyle fixes to meta_breadcrumb. Moving safeJS to the partial output.
This commit is contained in:
parent
a4b9df99b1
commit
86d7c8d001
2 changed files with 25 additions and 28 deletions
|
|
@ -1,10 +1,10 @@
|
||||||
{{- $breadcrumbScratch := newScratch -}}
|
{{ $breadcrumbScratch := newScratch -}}
|
||||||
{{- $crumbScratch := newScratch -}}
|
{{ $crumbScratch := newScratch -}}
|
||||||
{{- $crumbScratch.Set "itemListElement" (slice) -}}
|
{{ $crumbScratch.Set "itemListElement" (slice) -}}
|
||||||
{{- $breadPos := 0 -}}
|
{{ $breadPos := 0 -}}
|
||||||
{{- range .Ancestors.Reverse -}}
|
{{ range .Ancestors.Reverse -}}
|
||||||
{{- $breadPos = (add $breadPos 1) -}}
|
{{ $breadPos = (add $breadPos 1) -}}
|
||||||
{{- $crumbScratch.Add "itemListElement" (dict
|
{{ $crumbScratch.Add "itemListElement" (dict
|
||||||
"@type" "ListItem"
|
"@type" "ListItem"
|
||||||
"position" $breadPos
|
"position" $breadPos
|
||||||
"item" (dict
|
"item" (dict
|
||||||
|
|
@ -12,9 +12,9 @@
|
||||||
"name" .LinkTitle
|
"name" .LinkTitle
|
||||||
)
|
)
|
||||||
) -}}
|
) -}}
|
||||||
{{- end -}}
|
{{ end -}}
|
||||||
{{- $breadPos = (add $breadPos 1) -}}
|
{{ $breadPos = (add $breadPos 1) -}}
|
||||||
{{- $crumbScratch.Add "itemListElement" (dict
|
{{ $crumbScratch.Add "itemListElement" (dict
|
||||||
"@type" "ListItem"
|
"@type" "ListItem"
|
||||||
"position" $breadPos
|
"position" $breadPos
|
||||||
"item" (dict
|
"item" (dict
|
||||||
|
|
@ -22,8 +22,8 @@
|
||||||
"name" .LinkTitle
|
"name" .LinkTitle
|
||||||
)
|
)
|
||||||
) -}}
|
) -}}
|
||||||
{{- $breadcrumbScratch.SetInMap "breadcrumb" "@context" "https://schema.org" -}}
|
{{ $breadcrumbScratch.SetInMap "breadcrumb" "@context" "https://schema.org" -}}
|
||||||
{{- $breadcrumbScratch.SetInMap "breadcrumb" "@type" "BreadcrumbList" -}}
|
{{ $breadcrumbScratch.SetInMap "breadcrumb" "@type" "BreadcrumbList" -}}
|
||||||
{{- $breadcrumbScratch.SetInMap "breadcrumb" "itemListElement" ($crumbScratch.Get "itemListElement") -}}
|
{{ $breadcrumbScratch.SetInMap "breadcrumb" "itemListElement" ($crumbScratch.Get "itemListElement") -}}
|
||||||
{{- $jsonifiedBreadcrumb := $breadcrumbScratch.Get "breadcrumb" | jsonify (dict "indent" " " "prefix" " ") -}}
|
{{ $jsonifiedBreadcrumb := $breadcrumbScratch.Get "breadcrumb" | jsonify (dict "indent" " " "prefix" " ") -}}
|
||||||
{{- return $jsonifiedBreadcrumb -}}
|
{{ return ($jsonifiedBreadcrumb | safeJS) -}}
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,14 @@
|
||||||
<script type="application/ld+json">
|
<script type="application/ld+json">
|
||||||
{{- $blogSections := site.Params.blogSections | default (slice "blog" "post") }}
|
{{ $blogSections := site.Params.blogSections | default (slice "blog" "post") -}}
|
||||||
{{- $breadcrumbSections := site.Params.breadcrumbSections | default (slice) }}
|
{{ $breadcrumbSections := site.Params.breadcrumbSections | default (slice) -}}
|
||||||
{
|
{
|
||||||
"@context": "https://schema.org",
|
"@context": "https://schema.org",
|
||||||
{{ if .IsPage -}}
|
{{ if .IsPage -}}
|
||||||
"@type": {{ if in $blogSections .Section -}}
|
"@type": {{ if in $blogSections .Section }}"BlogPosting",{{ else }}"WebPage",
|
||||||
"BlogPosting",
|
{{ if in $breadcrumbSections .Section -}}
|
||||||
{{- else -}}
|
"breadcrumb": {{ partial "meta_breadcrumb_json_ld.html" . }},
|
||||||
"WebPage",
|
{{ end -}}
|
||||||
{{- if in $breadcrumbSections .Section }}
|
{{ end -}}
|
||||||
"breadcrumb": {{ safeJS (partial "meta_breadcrumb_json_ld.html" .) }},
|
|
||||||
{{- end -}}
|
|
||||||
{{- end }}
|
|
||||||
"headline": {{ .Title }},
|
"headline": {{ .Title }},
|
||||||
"datePublished": {{ .Date.Format "2006-01-02T15:04:05Z07:00" }},
|
"datePublished": {{ .Date.Format "2006-01-02T15:04:05Z07:00" }},
|
||||||
"dateModified": {{ .Lastmod.Format "2006-01-02T15:04:05Z07:00" }},
|
"dateModified": {{ .Lastmod.Format "2006-01-02T15:04:05Z07:00" }},
|
||||||
|
|
@ -24,9 +21,9 @@
|
||||||
{{ end -}}
|
{{ end -}}
|
||||||
{{ else -}}
|
{{ else -}}
|
||||||
"@type": "WebPage",
|
"@type": "WebPage",
|
||||||
{{- if in $breadcrumbSections .Section }}
|
{{ if in $breadcrumbSections .Section -}}
|
||||||
"breadcrumb": {{ safeJS (partial "meta_breadcrumb_json_ld.html" .) }},
|
"breadcrumb": {{ partial "meta_breadcrumb_json_ld.html" . }},
|
||||||
{{- end }}
|
{{ end -}}
|
||||||
"url" : {{ .Permalink }},
|
"url" : {{ .Permalink }},
|
||||||
"name": {{ .Title }},
|
"name": {{ .Title }},
|
||||||
{{ with $.Param "description" -}}
|
{{ with $.Param "description" -}}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue