Skip to content

Commit c399602

Browse files
committed
feat(meta): optimize og:image for featured image
Checking all possible featured image sources and resizing to 800px Resolves #144 Signed-off-by: Khusika Dhamar Gusti <[email protected]>
1 parent 1c8fbb1 commit c399602

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

layouts/_partials/head/meta.html

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,35 @@
44
<meta name="description" content="{{ $params.description | default .Site.Params.description }}">
55

66
{{- if ne $offline true -}}
7-
{{ partial "opengraph.html" . }}
8-
{{- template "_internal/twitter_cards.html" . -}}
7+
{{- $og := partial "opengraph.html" . -}}
8+
{{- $image := "" -}}
9+
{{- with or .Params.featuredimage .Params.featuredImage -}}
10+
{{- $original := resources.Get . -}}
11+
{{- with $original }}
12+
{{- $processed := .Resize "800x Lanczos" -}}
13+
{{- $image = $processed.Permalink -}}
14+
{{- end -}}
15+
{{- else -}}
16+
{{- with .Resources.GetMatch "featured-image" -}}
17+
{{- $processed := .Resize "800x Lanczos" -}}
18+
{{- $image = $processed.Permalink -}}
19+
{{- else -}}
20+
{{- range .Params.resources -}}
21+
{{- if eq .name "featured-image" -}}
22+
{{- $original := resources.Get .src -}}
23+
{{- with $original }}
24+
{{- $processed := .Resize "800x Lanczos" -}}
25+
{{- $image = $processed.Permalink -}}
26+
{{- end -}}
27+
{{- end -}}
28+
{{- end -}}
29+
{{- end -}}
30+
{{- end -}}
31+
{{- if $image }}
32+
{{- $og = replaceRE `<meta property="og:image" content="[^"]*">` (printf `<meta property="og:image" content="%s">` $image) $og -}}
33+
{{- end -}}
34+
{{- $og | safeHTML -}}
35+
{{- template "_internal/twitter_cards.html" . -}}
936
{{- end -}}
1037

1138
<meta name="application-name" content="{{ .Site.Params.app.title | default .Site.Title }}">

0 commit comments

Comments
 (0)