blob: f50016017e2c817428cfb7b6011cf1cbfc92e8d0 (
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
|
{{ $file := .Params.cover }}
{{ $coverAlt := .Params.coverAlt | default .Site.Params.coverAlt }}
<!-- Image processing configuration -->
{{ $imgProcConfig := partialCached "utilities/image-processing-config" . }}
{{ $resize := $imgProcConfig.autoResize }}
<!-- Default image path -->
{{ $imgPath := .Page.Param "imgPath" }}
{{ if $imgPath }}
{{ $file = path.Join $imgPath .Params.cover }}
{{ end }}
{{ $inputFile := false }}
{{ if and .Site.Params.cover (not .Params.cover) }}
{{ $inputFile = resources.Get .Site.Params.cover }}
{{ else }}
{{ $inputFile = .Page.Resources.GetMatch $file }}
{{ end }}
<!-- Avoid trying to convert unsupported formats (GIF, SVG, etc) -->
{{ $supportedFormats := (slice "jpeg" "png" "tiff") }}
<!-- Initialization -->
{{ $fallbackOptions := false }}
{{ $openGraphImage := false }}
{{ $twitterImage := false }}
{{ $schemaCover := false }}
{{ if and $inputFile $resize }}
{{ if in $supportedFormats ($inputFile.MediaType.SubType) }}
<!-- Generate images for Open Graph, Twitter Cards and also Schema -->
{{ with $inputFile }}
<!-- Make sure "tiff" is converted to a format with better support -->
{{ if eq .MediaType.SubType "tiff" }}
{{ $fallbackOptions = $imgProcConfig.fallbackOptions }}
{{ end }}
{{ $openGraphImage = (.Fill (printf "%s %s" $imgProcConfig.openGraphFillOptions $fallbackOptions)) }}
{{ $twitterImage = (.Fill (printf "%s %s" $imgProcConfig.twitterFillOptions $fallbackOptions)) }}
{{ end }}
{{ if and (in .Site.Params.mainSections .Section) (not .Params.sitemapExclude) }}
{{ $schemaCover = (slice ($twitterImage.Permalink) ($openGraphImage.Permalink)) }}
{{ end }}
{{ end }}
{{ else }}
{{ with $inputFile }}
{{ $openGraphImage = . }}
{{ $twitterImage = $openGraphImage }}
{{ if and (in $.Site.Params.mainSections $.Section) (not $.Params.sitemapExclude) }}
{{ $schemaCover = (slice $inputFile.Permalink) }}
{{ end }}
{{ end }}
{{ end }}
{{ return (dict "openGraphImage" $openGraphImage "coverAlt" $coverAlt "twitterImage" $twitterImage "schemaCover" $schemaCover) }}
|