diff --git a/config/_default/params.toml b/config/_default/params.toml index ffaf9de74ad..bc462b219d5 100644 --- a/config/_default/params.toml +++ b/config/_default/params.toml @@ -125,10 +125,9 @@ show_related = {docs = true, page = true, post = true, project = true, publicati ############################ # Default image for social sharing and search engines. Place image in `static/` folder and specify 'img/[image name]' here. -sharing_image = "img/FORRT_banner.svg" - -# Twitter username (without @). Used when a visitor shares your site on Twitter. -twitter = "FORRTproject" +sharing_image = "img/FORRTbanner.webp" +# Alt text for the sharing image (accessibility and og:image:alt). Defaults to site title if unset. +sharing_image_alt = "FORRT - Framework for Open and Reproducible Research Training" ############################ ## Regional Settings diff --git a/layouts/partials/site_head.html b/layouts/partials/site_head.html index c4498ce01cb..0f45cd7cdca 100644 --- a/layouts/partials/site_head.html +++ b/layouts/partials/site_head.html @@ -54,6 +54,15 @@ {{ $desc = $superuser_role }} {{ end }} + {{/* Shorter description for social previews (avoids mid-word truncation). */}} + {{ $og_desc := "" }} + {{ if .Params.sharing_description }} + {{ $og_desc = .Params.sharing_description }} + {{ else if .Params.og_description }} + {{ $og_desc = .Params.og_description }} + {{ else }} + {{ $og_desc = printf "%.200s" $desc }} + {{ end }} {{ range .Translations }} @@ -186,36 +195,57 @@ {{ $avatar_image := (.Resources.ByType "image").GetMatch "avatar*" }} {{ $has_logo := fileExists "assets/images/logo.webp" | or (fileExists "assets/images/logo.svg") }} {{ $og_image := "" }} - {{ $twitter_card := "summary_large_image" }} + {{ $og_image_width := 0 }} + {{ $og_image_height := 0 }} {{ if (and (eq .Kind "taxonomy") $avatar_image) }} - {{ $og_image = ($avatar_image.Fill "270x270 Center").Permalink }}{{/* Match image proc in About widget. */}} - {{ $twitter_card = "summary" }} + {{ $avatar_fill := $avatar_image.Fill "270x270 Center" }} + {{ $og_image = $avatar_fill.Permalink }} + {{ $og_image_width = $avatar_fill.Width }} + {{ $og_image_height = $avatar_fill.Height }} {{ else if $featured_image }} {{ $og_image = $featured_image.Permalink }} + {{ $og_image_width = $featured_image.Width }} + {{ $og_image_height = $featured_image.Height }} {{ else if .Params.header.image }} {{ $og_image = printf "%s/%s" $media_dir .Params.header.image | absURL }} {{ else if site.Params.sharing_image }} {{ $og_image = site.Params.sharing_image | absURL }} + {{ with images.Config (printf "/static/%s" site.Params.sharing_image) }} + {{ $og_image_width = .Width }} + {{ $og_image_height = .Height }} + {{ end }} {{ else if $has_logo }} {{ $og_image = (partial "functions/get_logo" (dict "constraint" "fit" "size" 300)).Permalink }} - {{ $twitter_card = "summary" }} {{ else }} {{ $og_image = (partial "functions/get_icon" 512).Permalink }} - {{ $twitter_card = "summary" }} {{ end }} {{ $scr.Set "og_image" $og_image }}{{/* Set `og_image` globally for `rss.xml`. */}} - - {{ with site.Params.twitter }} - - - {{ end }} + {{ $og_image_alt := site.Params.sharing_image_alt | default site.Title }} + {{ if .Params.sharing_image_alt }}{{ $og_image_alt = .Params.sharing_image_alt }}{{ end }} - - + {{/* Sharing title: allow override, else append site name for context in previews. */}} + {{ $og_title := "" }} + {{ if .Params.sharing_title }} + {{ $og_title = .Params.sharing_title }} + {{ else if .Params.og_title }} + {{ $og_title = .Params.og_title }} + {{ else if .IsHome }} + {{ $og_title = site.Title }} + {{ else }} + {{ $og_title = printf "%s | %s" .Title site.Title }} + {{ end }} + + {{- with $og_image -}} - + {{- if (and (gt $og_image_width 0) (gt $og_image_height 0)) -}} + + + {{- end -}} + {{- with $og_image_alt -}} + + {{- end -}} {{- end -}} {{ if .IsPage }} diff --git a/static/img/FORRTbanner.webp b/static/img/FORRTbanner.webp new file mode 100644 index 00000000000..961b6fe25cc Binary files /dev/null and b/static/img/FORRTbanner.webp differ