summaryrefslogtreecommitdiff
path: root/themes/CodeIT/layouts/partials/head/seo.html
blob: d431ad0669e557cb4a04f0a2a210a54267b33e66 (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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
{{- $params := .Scratch.Get "params" -}}

{{- with .Site.Params.verification.google -}}
    <meta name="google-site-verification" content="{{ . }}" />
{{- end -}}
{{- with .Site.Params.verification.bing -}}
    <meta name="msvalidate.01" content="{{ . }}" />
{{- end -}}
{{- with .Site.Params.verification.yandex -}}
    <meta name="yandex-verification" content="{{ . }}" />
{{- end -}}
{{- with .Site.Params.verification.pinterest -}}
    <meta name="p:domain_verify" content="{{ . }}" />
{{- end -}}
{{- with .Site.Params.verification.baidu -}}
    <meta name="baidu-site-verification" content="{{ . }}" />
{{- end -}}

{{- /* Home SEO */ -}}
{{- if .IsHome -}}
    <script type="application/ld+json">
    {
        "@context": "http://schema.org",
        "@type": "WebSite",
        "url": "{{ .Permalink }}",
        {{- with .Site.LanguageCode -}}
            "inLanguage": "{{ . }}",
        {{- end -}}
        {{- with .Site.Author.name -}}
            "author": {
                "@type": "Person",
                "name": {{ . | safeHTML }}
            },
        {{- end -}}
        {{- with .Site.Params.description -}}
            "description": {{ . | safeHTML }},
        {{- end -}}
        {{- $image := .Site.Params.seo.image -}}
        {{- with dict "Path" $image "Resources" .Resources | partial "function/resource.html" -}}
            "image": {
                "@type": "ImageObject",
                "url": "{{ .Permalink }}",
                "width": {{ .Width }},
                "height": {{ .Height }}
            },
        {{- else -}}
            {{- with $image -}}
                "image": "{{ . | absURL }}",
            {{- end -}}
        {{- end -}}
        {{- with .Site.Params.seo.thumbnailUrl -}}
            {{- with dict "Path" . "Resources" $.Resources | partial "function/resource.html" -}}
                "thumbnailUrl": "{{ .Permalink }}",
            {{- else -}}
                "thumbnailUrl": "{{ . | absURL }}",
            {{- end -}}
        {{- end -}}
        {{- with .Site.Copyright -}}
            "license": "{{ . | safeHTML }}",
        {{- end -}}
        "name": {{ .Site.Title | safeHTML }}
    }
    </script>

{{- /* Page SEO */ -}}
{{- else if .IsPage -}}
    <script type="application/ld+json">
    {
        "@context": "http://schema.org",
        "@type": "BlogPosting",
        "headline": {{ .Title | safeHTML }},
        "inLanguage": "{{ .Site.LanguageCode }}",
        "mainEntityOfPage": {
            "@type": "WebPage",
            "@id": "{{ .Permalink }}"
        },
        {{- $images := $params.seo.images | default slice -}}
        {{- if not $images -}}
            {{- with .Resources.GetMatch "featured-image-preview" -}}
                {{- $images = slice "featured-image-preview" -}}
            {{- end -}}
            {{- with .Resources.GetMatch "featured-image" -}}
                {{- $images = slice "featured-image" -}}
            {{- end -}}
        {{- end -}}
        {{- with .Site.Params.seo.image -}}
            {{- $images = $images | default (slice .) -}}
        {{- end -}}
        {{- with $images -}}
            "image": [
                {{- range $index, $value := . -}}
                    {{- if gt $index 0 }},{{ end -}}
                    {{- with dict "Path" $value "Resources" $.Resources | partial "function/resource.html" -}}
                        {
                            "@type": "ImageObject",
                            "url": "{{ .Permalink }}",
                            "width": {{ .Width }},
                            "height": {{ .Height }}
                        }
                    {{- else -}}
                        {{- with $value -}}
                            "{{ . | absURL }}"
                        {{- end -}}
                    {{- end -}}
                {{- end -}}
            ],
        {{- end -}}
        "genre": "{{ .Type }}",
        {{- with .Params.tags -}}
            "keywords": "{{ delimit . ", " }}",
        {{- end -}}
        "wordcount": {{ .WordCount }},
        "url": "{{ .Permalink }}",
        {{- if not .PublishDate.IsZero -}}
            "datePublished": {{ .PublishDate.Format "2006-01-02T15:04:05-07:00" | safeHTML }},
        {{- else if not .Date.IsZero -}}
            "datePublished": {{ .Date.Format "2006-01-02T15:04:05-07:00" | safeHTML }},
        {{- end -}}
        {{- with .Lastmod -}}
            "dateModified": {{ .Format "2006-01-02T15:04:05-07:00" | safeHTML }},
        {{- end -}}
        {{- with .Site.Copyright -}}
            "license": {{ . | safeHTML }},
        {{- end -}}
        {{- $publisher := .Params.author | default .Site.Author.name | default (T "author") | dict "name" -}}
        {{- $publisher = $params.seo.publisher | default dict | merge $publisher -}}
        "publisher": {
            "@type": "Organization",
            "name": {{ $publisher.name | safeHTML }}
            {{- $logo := $publisher.logoUrl -}}
            {{- with dict "Path" $logo "Resources" .Resources | partial "function/resource.html" -}}
                ,"logo": {
                    "@type": "ImageObject",
                    "url": "{{ .Permalink }}",
                    "width": {{ .Width }},
                    "height": {{ .Height }}
                }
            {{- else -}}
                {{- with $logo -}}
                    ,"logo": "{{ . | absURL }}"
                {{- end -}}
            {{- end -}}
        },
        {{- with .Params.author | default .Site.Author.name | default (T "author") -}}
            "author": {
                "@type": "Person",
                "name": {{ . | safeHTML }}
            },
        {{- end -}}
        "description": {{ .Description | safeHTML }}
    }
    </script>
{{- end -}}