aboutsummaryrefslogtreecommitdiff
path: root/layouts/partials/social_card.html
blob: 61914ef4cf98c35591f4d56d504907407ac337cf (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
<!-- Dynamic social card generation -->
{{ $font := resources.Get "fonts/FiraMono-Bold.ttf" }}
{{ $fg := resources.Get "images/social_card_fg.png"}}
{{ $bg := resources.Get "images/social_card_bg.png"}}

{{ if gt (len .Title) 40 }}
  {{ $fg = $fg.Filter (images.Text .Title (dict
    "font" $font
    "color" "#fafafa"
    "size" 95
    "linespacing" 16
    "x" 0
    "y" 0
  )) }}
{{ else }}
  {{ $fg = $fg.Filter (images.Text .Title (dict
    "font" $font
    "color" "#fafafa"
    "size" 130
    "linespacing" 20
    "x" 0
    "y" 0
  )) }}
{{ end }}

{{ $date := .Date.Format (default "2006-01-02" .Site.Params.dateFormat) }}
{{ $author := (default $.Site.Params.author.name ($.Param "author.name")) }}
{{ $byline := (printf "%s | %s" $author $date) }}

{{ $fg = $fg.Filter (images.Text $byline (dict
    "font" $font
    "color" "#898a8d"
    "size" 60
    "linespacing" 30
    "x" 0
    "y" 425
)) }}

{{ $card := $bg.Filter (images.Overlay $fg 112 140 ) }}
{{ $card := $card.Resize "900x webp q100" }}

<meta itemprop="name" content="{{ .Title }}">
<meta itemprop="description" content="{{ with .Description }}{{ . }}{{ else }}{{if .IsPage}}{{ .Summary }}{{ else }}{{ with .Site.Params.description }}{{ . }}{{ end }}{{ end }}{{ end }}">
{{- if .IsPage -}}
{{- $iso8601 := "2006-01-02T15:04:05-07:00" -}}
{{ with .PublishDate }}<meta itemprop="datePublished" {{ .Format $iso8601 | printf "content=%q" | safeHTMLAttr }} />{{ end}}
{{ with .Lastmod }}<meta itemprop="dateModified" {{ .Format $iso8601 | printf "content=%q" | safeHTMLAttr }} />{{ end}}
<meta itemprop="wordCount" content="{{ .WordCount }}">
<meta itemprop="image" content="{{ $card.Permalink | absURL }}"/>
<meta itemprop="keywords" content="{{ if .IsPage}}{{ range $index, $tag := .Params.tags }}{{ $tag }},{{ end }}{{ else }}{{ range $plural, $terms := .Site.Taxonomies }}{{ range $term, $val := $terms }}{{ printf "%s," $term }}{{ end }}{{ end }}{{ end }}" />
{{- end -}}