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

{{- end -}}