summaryrefslogtreecommitdiffstats
path: root/layouts/partials/schema.org/article.html
blob: ff1558be6771fffaa111ec530fbee2336c2f061c (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
{{- /* Get schema type. */}}
{{ $schemaType := "Article" }}
{{ if or (eq .Type "post") (eq .Type "posts") }}
  {{ $schemaType = "BlogPosting" }}
{{ end -}}

{{- $publisher := site.Params.seo.publisher | default site.Title }}
{{ $logo := resources.Get (site.Params.assets.logo | default "/img/open-graph-logo.png") }}
{{ $logo = $logo.Resize "96x96" -}}

<script type="application/ld+json">
    {
        "@context": "https://schema.org",
        "@type": {{ $schemaType }},
        "mainEntityOfPage": {
            "@type": "WebPage",
            "@id": {{ .Permalink }}
        },
        "headline": {{ partial "title.html" . | htmlUnescape }},{{ if .Params.featured_image }}
        {{ $image := .Resources.GetMatch .Params.featured_image -}}
        "image": [
            {{ $image.Permalink }}
        ],{{ end }}
        "datePublished": {{ .Date.Format "2006-01-02T15:04:05Z07:00" }},
        "dateModified": {{ .Lastmod.Format "2006-01-02T15:04:05Z07:00" }},
        {{- if .Params.author }}
            {{- $authorType := (printf "%T" .Params.author) }}
            {{- if eq $authorType "string" }}
                "author": {
                    "@type": "Person",
                    "name": {{ .Params.author }}
                },
            {{- else if eq $authorType "[]string" }}
                "author": [
                    {{ range $i, $author := .Params.author }}{{ if $i }},{{ end }}
                    {
                        "@type": "Person",
                        "name": {{ $author }}
                    }{{ end }}
                ],
            {{- end }}
        {{- else }}
            {{- with site.Author.name }}
                "author": {
                    "@type": "Person",
                    "name": {{ . }}
                    {{ with site.Author.twitter }},
                        "url": "https://twitter.com/{{ . }}"
                    {{ end }}
                },
            {{- end }}
        {{- end }}
        "publisher": {
            "@type": "Organization",
            "name": {{ $publisher }},
            "logo": {
                "@type": "ImageObject",
                "url": {{ $logo.Permalink | absURL }}
            }
        },
        "description": {{ partial "description.html" . }}
    }
</script>