diff --git a/config/_default/params.toml b/config/_default/params.toml index eb74615..efee285 100644 --- a/config/_default/params.toml +++ b/config/_default/params.toml @@ -14,3 +14,6 @@ email = "valknar@pivoine.art" [visualizer] particleCount = 5000 fftSize = 512 + +[images] + default = "/images/og-default.png" diff --git a/layouts/partials/head/opengraph.html b/layouts/partials/head/opengraph.html index 7dec406..81479a5 100755 --- a/layouts/partials/head/opengraph.html +++ b/layouts/partials/head/opengraph.html @@ -1,7 +1,19 @@ {{- $title := .Title | default .Site.Title -}} {{- $desc := .Description | default .Summary | default .Site.Params.description | plainify | truncate 200 -}} -{{- $image := .Params.image | default "/images/og-default.png" -}} -{{- if not (strings.HasPrefix $image "http") -}} + +{{/* Resolve image: page resource cover.* > .Params.image > site default */}} +{{- $image := "" -}} +{{- with .Resources.GetMatch "cover.*" -}} + {{- $img := .Resize "1200x webp q90" -}} + {{- $image = $img.Permalink -}} +{{- else -}} + {{- with $.Params.image -}} + {{- $image = . -}} + {{- else -}} + {{- $image = $.Site.Params.images.default | default "/images/og-default.png" -}} + {{- end -}} +{{- end -}} +{{- if and $image (not (strings.HasPrefix $image "http")) -}} {{- $image = $image | absURL -}} {{- end -}} diff --git a/layouts/partials/head/twitter.html b/layouts/partials/head/twitter.html index b89f1be..c4e2f50 100755 --- a/layouts/partials/head/twitter.html +++ b/layouts/partials/head/twitter.html @@ -1,11 +1,23 @@ {{- $title := .Title | default .Site.Title -}} {{- $desc := .Description | default .Summary | default .Site.Params.description | plainify | truncate 200 -}} -{{- $image := .Params.image | default "/images/og-default.png" -}} -{{- if not (strings.HasPrefix $image "http") -}} + +{{/* Resolve image: page resource cover.* > .Params.image > site default */}} +{{- $image := "" -}} +{{- with .Resources.GetMatch "cover.*" -}} + {{- $img := .Resize "1200x webp q90" -}} + {{- $image = $img.Permalink -}} +{{- else -}} + {{- with $.Params.image -}} + {{- $image = . -}} + {{- else -}} + {{- $image = $.Site.Params.images.default | default "/images/og-default.png" -}} + {{- end -}} +{{- end -}} +{{- if and $image (not (strings.HasPrefix $image "http")) -}} {{- $image = $image | absURL -}} {{- end -}} -{{/* Determine card type */}} +{{/* Determine card type - use large image when we have one */}} {{- $cardType := "summary" -}} {{- if $image -}} {{- $cardType = "summary_large_image" -}} diff --git a/static/images/og-default.png b/static/images/og-default.png new file mode 100644 index 0000000..8ad5d5e Binary files /dev/null and b/static/images/og-default.png differ