schema_json.html (3951B)
1 {{ if .IsHome }} 2 <script type="application/ld+json"> 3 { 4 "@context": "https://schema.org", 5 "@type": "{{- ( site.Params.schema.publisherType | default "Organization") | title -}}", 6 "name": {{ site.Title }}, 7 "url": {{ site.Home.Permalink }}, 8 "description": {{ site.Params.description | plainify | truncate 180 | safeHTML }}, 9 {{- if (eq site.Params.schema.publisherType "Person") }} 10 "image": {{ site.Params.assets.favicon | default "favicon.ico" | absURL }}, 11 {{- else }} 12 "logo": {{ site.Params.assets.favicon | default "favicon.ico" | absURL }}, 13 {{- end }} 14 "sameAs": [ 15 {{- if site.Params.schema.sameAs }} 16 {{ range $i, $e := site.Params.schema.sameAs }}{{ if $i }}, {{ end }}{{ trim $e " " }}{{ end }} 17 {{- else}} 18 {{ range $i, $e := site.Params.SocialIcons }}{{ if $i }}, {{ end }}{{ trim $e.url " " | safeURL }}{{ end }} 19 {{- end}} 20 ] 21 } 22 </script> 23 {{- else if (or .IsPage .IsSection) }} 24 {{/* BreadcrumbList */}} 25 {{- $url := replace .Parent.Permalink ( printf "%s" site.Home.Permalink) "" }} 26 {{- $lang_url := strings.TrimPrefix ( printf "%s/" .Lang) $url }} 27 {{- $bc_list := (split $lang_url "/")}} 28 29 {{- $scratch := newScratch }} 30 <script type="application/ld+json"> 31 { 32 "@context": "https://schema.org", 33 "@type": "BreadcrumbList", 34 "itemListElement": [ 35 {{- range $index, $element := $bc_list }} 36 37 {{- $scratch.Add "path" (printf "%s/" $element ) | safeJS }} 38 {{- $bc_pg := site.GetPage ($scratch.Get "path") -}} 39 40 {{- if (and ($bc_pg) (gt (len . ) 0))}} 41 {{- if (and $index)}}, {{end }} 42 { 43 "@type": "ListItem", 44 "position": {{ add 1 $index }}, 45 "name": {{ $bc_pg.Name }}, 46 "item": {{ $bc_pg.Permalink | safeHTML }} 47 } 48 {{- end }} 49 50 {{- end }} 51 {{- /* self-page addition */ -}} 52 {{- if (ge (len $bc_list) 2) }}, {{end }} 53 { 54 "@type": "ListItem", 55 "position": {{len $bc_list}}, 56 "name": {{ .Name }}, 57 "item": {{ .Permalink | safeHTML }} 58 } 59 ] 60 } 61 </script> 62 {{- if .IsPage }} 63 <script type="application/ld+json"> 64 { 65 "@context": "https://schema.org", 66 "@type": "BlogPosting", 67 "headline": {{ .Title | plainify}}, 68 "name": "{{ .Title | plainify }}", 69 "description": {{ with .Description | plainify }}{{ . }}{{ else }}{{ .Summary | plainify }}{{ end -}}, 70 "keywords": [ 71 {{- if .Params.keywords }} 72 {{ range $i, $e := .Params.keywords }}{{ if $i }}, {{ end }}{{ $e }}{{ end }} 73 {{- else }} 74 {{ range $i, $e := .Params.tags }}{{ if $i }}, {{ end }}{{ $e }}{{ end }} 75 {{- end }} 76 ], 77 "articleBody": {{ .Content | safeJS | htmlUnescape | plainify }}, 78 "wordCount" : "{{ .WordCount }}", 79 "inLanguage": {{ .Language.Lang | default "en-us" }}, 80 {{ if .Params.cover.image -}} 81 "image": 82 {{- if (ne .Params.cover.relative true) -}} 83 {{ .Params.cover.image | absURL }}, 84 {{- else -}} 85 {{ (path.Join .RelPermalink .Params.cover.image ) | absURL }}, 86 {{- end}} 87 {{- else }} 88 {{- $images := partial "templates/_funcs/get-page-images" . -}} 89 {{- with index $images 0 -}} 90 "image": {{ .Permalink }}, 91 {{- end }} 92 {{- end -}} 93 "datePublished": {{ .PublishDate }}, 94 "dateModified": {{ .Lastmod }}, 95 {{- with (.Params.author | default site.Params.author) }} 96 "author": 97 {{- if (or (eq (printf "%T" .) "[]string") (eq (printf "%T" .) "[]interface {}")) -}} 98 [{{- range $i, $v := . -}} 99 {{- if $i }}, {{end -}} 100 { 101 "@type": "Person", 102 "name": {{ $v }} 103 } 104 {{- end }}], 105 {{- else -}} 106 { 107 "@type": "Person", 108 "name": {{ . }} 109 }, 110 {{- end -}} 111 {{- end }} 112 "mainEntityOfPage": { 113 "@type": "WebPage", 114 "@id": {{ .Permalink | safeHTML }} 115 }, 116 "publisher": { 117 "@type": "{{- ( site.Params.schema.publisherType | default "Organization") | title -}}", 118 "name": {{ site.Title }}, 119 "logo": { 120 "@type": "ImageObject", 121 "url": {{ site.Params.assets.favicon | default "favicon.ico" | absURL }} 122 } 123 } 124 } 125 </script> 126 {{- end }}{{/* .IsPage end */}} 127 128 {{- end -}}