~ruther/blog

ref: b8ec0e6881318f4adbd4ae68277a540c0eacf203 blog/themes/poison/layouts/partials/head/meta.html -rw-r--r-- 5.5 KiB
b8ec0e68 — Rutherther Initial commit 9 months ago
                                                                                
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
{{ .Scratch.Set "title" .Site.Title }}

{{ .Scratch.Set "publisherIcon" .Site.Params.favicon }}
{{ if .Site.Params.publisherIcon }}
    {{ .Scratch.Set "publisherIcon" .Site.Params.publisher_icon }}
{{ end }}

{{ if eq .Kind "home" }}
  {{ .Scratch.Set "title" $.Site.Params.brand }}
  {{ .Scratch.Set "description" .Site.Params.Description }}
{{ else }}
  {{ .Scratch.Set "description" .Description }}
{{ end }}

{{ if .IsSection }}
  {{ .Scratch.Set "title" ($.Site.Params.brand) }}
  {{ .Scratch.Add "title" " - " }}
  {{ .Scratch.Add "title" .LinkTitle }}
{{ end }}

{{ if .IsPage }}
  {{ .Scratch.Set "title" ($.Site.Params.brand) }}
  {{ .Scratch.Add "title" " - " }}
  {{ .Scratch.Add "title" .LinkTitle }}
{{ end }}

{{ "<!-- Open Graph image and Twitter Card metadata -->" | safeHTML }}
{{ $image_path := .Params.image | default .Site.Params.og_image -}}
{{ with $image_path }}
  {{ $image_path_local :=  printf "assets/%s" $image_path -}}
  {{ $image_ext := trim (path.Ext $image_path | lower) "." -}}
  {{ if fileExists $image_path_local -}} 
    {{ $image_path:= resources.Get $image_path}}
    <meta property="og:image" content="{{ $image_path.RelPermalink }}" />
    {{/* If not SVG, read image aspect ratio and define Twitter Card and Open Graph width and height  */ -}}
    {{ if ne $image_ext "svg" -}}
      {{ with (imageConfig $image_path_local) -}}
        {{ if (and (gt .Width 144) (gt .Height 144)) -}}
          <meta name="twitter:image" content="{{ $image_path.RelPermalink }}"/>
          <meta name="twitter:card" content="summary{{ if (and (gt .Width 300) (gt .Height 157) (not (eq .Width .Height))) }}_large_image{{ end }}">
        {{ end -}}
        <meta property="og:image:width" content="{{ .Width }}">
        <meta property="og:image:height" content="{{ .Height }}">
      {{ end -}}
    {{ end -}}
    <meta property="og:image:type" content="image/{{ if eq $image_ext `svg` }}svg+xml{{ else }}{{ replaceRE `^jpg$` `jpeg` $image_ext }}{{ end }}">
  {{ end -}}
{{ end -}}

<!-- Title Tags -->
<title itemprop="name">{{ .Scratch.Get "title" }}</title>
<meta property="og:title" content={{ .Scratch.Get "title" }} />
<meta name="twitter:title" content={{ .Scratch.Get "title" }} />
<meta itemprop="name" content={{ .Scratch.Get "title" }} />
<meta name="application-name" content={{ .Scratch.Get "title" }} />
<meta property="og:site_name" content="{{ .Site.Title }}" />

<!-- Description Tags -->
<meta name="description" content="{{ .Scratch.Get "description" }}" />
<meta itemprop="description" content="{{ .Scratch.Get "description" }}" />
<meta property="og:description" content="{{ .Scratch.Get "description" }}" />
<meta name="twitter:description" content="{{ .Scratch.Get "description" }}" />

<!-- Link Tags -->
<base href="{{ .Permalink }}" />
<link rel="canonical" href="{{ .Permalink }}" itemprop="url" />
<meta name="url" content="{{ .Permalink }}" />
<meta name="twitter:url" content="{{ .Permalink }}" />
<meta property="og:url" content="{{ .Permalink }}" />

<!-- Date Tags -->
<meta property="og:updated_time" content="{{ .Lastmod.Format "2006-01-02T15:04:05Z07:00" }}" />

<!-- Sitemap & Alternate Outputs -->
<link rel="sitemap" type="application/xml" title="Sitemap" href='{{ "sitemap.xml" | absURL }}' />
{{ range .AlternativeOutputFormats -}}
    {{ printf `<link href="%s" rel="%s" type="%s" title="%s" />` .Permalink .Rel .MediaType.Type $.Site.Title | safeHTML }}
{{ end -}}

<!-- Search Engine Crawler Tags -->
<meta name="robots" content="index,follow" />
<meta name="googlebot" content="index,follow" />

<!-- Social Media Tags -->
{{if (or (ne .Site.Params.twitter_url nil) (ne .Site.Params.x_url nil))}}
  {{ $twitter_user := index (split (default .Site.Params.twitter_url .Site.Params.x_url) "/") 3 }}
    <meta name="twitter:site" content="@{{ $twitter_user }}" />
    <meta name="twitter:creator" content="@{{ $twitter_user }}" />
{{end}}
<meta property="fb:admins" content="{{ .Site.Params.fb.admins }}" />

<!-- Other Tags -->
<meta name="apple-mobile-web-app-title" content="{{ .Site.Title }}" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />

<!-- Article Specific Tags -->
<!-- To make sure this renders only in the article page, we check the section -->
{{ if and (eq .Section "posts") (.Page.IsNode) }}
<!-- Pagination meta tags for list pages only -->
{{ $paginator := .Paginate (where .Pages "Type" "posts") }}
{{ if $paginator }}
  <link rel="first" href="{{ $paginator.First.URL }}" />
  <link rel="last" href="{{ $paginator.Last.URL }}" />
  {{ if $paginator.HasPrev }}
    <link rel="prev" href="{{ $paginator.Prev.URL }}" />
  {{end }}
  {{ if $paginator.HasNext }}
    <link rel="next" href="{{ $paginator.Next.URL }}" />
  {{end }}
{{end }}

<meta property="og:type" content="article" />
<meta property="article:publisher" content="{{ .Site.Params.facebook_url }}" />
<meta property="og:article:published_time" content="{{ .Date.Format "2006-01-02T15:04:05Z07:00" }}" />
<meta property="article:published_time" content="{{ .Date.Format "2006-01-02T15:04:05Z07:00"  }}" />

{{ with (or (.Params.Author) (.Site.Language.Params.Author.Name)) }}
  <meta property="og:article:author" content="{{ . }}" />
  <meta property="article:author" content="{{ . }}" />
  <meta name="author" content="{{ . }}" />
{{ end }}

{{ with.Params.category }}
  <meta name="news_keywords" content="{{ index . 0 }}" />
  <meta property="article:section" content="{{ index . 0 }}" />
{{ end }}

{{ end }}

<!-- Hugo Generator Attribution -->
{{ hugo.Generator }}