Skip to content

Commit aae474c

Browse files
fix:Use FORRT banner as default social sharing image (#696)
* fix:image preview * fix. Open Graph issues and preview long texts * preview Page title | Site name --------- Co-authored-by: Lukas Wallrich <lukas.wallrich@gmail.com>
1 parent 07d7335 commit aae474c

3 files changed

Lines changed: 46 additions & 17 deletions

File tree

config/_default/params.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,10 +125,9 @@ show_related = {docs = true, page = true, post = true, project = true, publicati
125125
############################
126126

127127
# Default image for social sharing and search engines. Place image in `static/` folder and specify 'img/[image name]' here.
128-
sharing_image = "img/FORRT_banner.svg"
129-
130-
# Twitter username (without @). Used when a visitor shares your site on Twitter.
131-
twitter = "FORRTproject"
128+
sharing_image = "img/FORRTbanner.webp"
129+
# Alt text for the sharing image (accessibility and og:image:alt). Defaults to site title if unset.
130+
sharing_image_alt = "FORRT - Framework for Open and Reproducible Research Training"
132131

133132
############################
134133
## Regional Settings

layouts/partials/site_head.html

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,15 @@
5454
{{ $desc = $superuser_role }}
5555
{{ end }}
5656
<meta name="description" content='{{ printf "%.254s" $desc }}'>
57+
{{/* Shorter description for social previews (avoids mid-word truncation). */}}
58+
{{ $og_desc := "" }}
59+
{{ if .Params.sharing_description }}
60+
{{ $og_desc = .Params.sharing_description }}
61+
{{ else if .Params.og_description }}
62+
{{ $og_desc = .Params.og_description }}
63+
{{ else }}
64+
{{ $og_desc = printf "%.200s" $desc }}
65+
{{ end }}
5766

5867
{{ range .Translations }}
5968
<link rel="alternate" hreflang="{{ .Lang }}" href="{{ .Permalink }}">
@@ -186,36 +195,57 @@
186195
{{ $avatar_image := (.Resources.ByType "image").GetMatch "avatar*" }}
187196
{{ $has_logo := fileExists "assets/images/logo.webp" | or (fileExists "assets/images/logo.svg") }}
188197
{{ $og_image := "" }}
189-
{{ $twitter_card := "summary_large_image" }}
198+
{{ $og_image_width := 0 }}
199+
{{ $og_image_height := 0 }}
190200
{{ if (and (eq .Kind "taxonomy") $avatar_image) }}
191-
{{ $og_image = ($avatar_image.Fill "270x270 Center").Permalink }}{{/* Match image proc in About widget. */}}
192-
{{ $twitter_card = "summary" }}
201+
{{ $avatar_fill := $avatar_image.Fill "270x270 Center" }}
202+
{{ $og_image = $avatar_fill.Permalink }}
203+
{{ $og_image_width = $avatar_fill.Width }}
204+
{{ $og_image_height = $avatar_fill.Height }}
193205
{{ else if $featured_image }}
194206
{{ $og_image = $featured_image.Permalink }}
207+
{{ $og_image_width = $featured_image.Width }}
208+
{{ $og_image_height = $featured_image.Height }}
195209
{{ else if .Params.header.image }}
196210
{{ $og_image = printf "%s/%s" $media_dir .Params.header.image | absURL }}
197211
{{ else if site.Params.sharing_image }}
198212
{{ $og_image = site.Params.sharing_image | absURL }}
213+
{{ with images.Config (printf "/static/%s" site.Params.sharing_image) }}
214+
{{ $og_image_width = .Width }}
215+
{{ $og_image_height = .Height }}
216+
{{ end }}
199217
{{ else if $has_logo }}
200218
{{ $og_image = (partial "functions/get_logo" (dict "constraint" "fit" "size" 300)).Permalink }}
201-
{{ $twitter_card = "summary" }}
202219
{{ else }}
203220
{{ $og_image = (partial "functions/get_icon" 512).Permalink }}
204-
{{ $twitter_card = "summary" }}
205221
{{ end }}
206222
{{ $scr.Set "og_image" $og_image }}{{/* Set `og_image` globally for `rss.xml`. */}}
207-
<meta property="twitter:card" content="{{ $twitter_card }}">
208-
{{ with site.Params.twitter }}
209-
<meta property="twitter:site" content="@{{ . }}">
210-
<meta property="twitter:creator" content="@{{ . }}">
211-
{{ end }}
223+
{{ $og_image_alt := site.Params.sharing_image_alt | default site.Title }}
224+
{{ if .Params.sharing_image_alt }}{{ $og_image_alt = .Params.sharing_image_alt }}{{ end }}
212225
<meta property="og:site_name" content="{{ site.Title }}">
213226
<meta property="og:url" content="{{ .Permalink }}">
214-
<meta property="og:title" content="{{ if not .IsHome }}{{ .Title }}{{ else }}{{ site.Title }}{{ end }}">
215-
<meta property="og:description" content='{{ printf "%.254s" $desc }}'>
227+
{{/* Sharing title: allow override, else append site name for context in previews. */}}
228+
{{ $og_title := "" }}
229+
{{ if .Params.sharing_title }}
230+
{{ $og_title = .Params.sharing_title }}
231+
{{ else if .Params.og_title }}
232+
{{ $og_title = .Params.og_title }}
233+
{{ else if .IsHome }}
234+
{{ $og_title = site.Title }}
235+
{{ else }}
236+
{{ $og_title = printf "%s | %s" .Title site.Title }}
237+
{{ end }}
238+
<meta property="og:title" content="{{ $og_title }}">
239+
<meta property="og:description" content='{{ $og_desc }}'>
216240
{{- with $og_image -}}
217241
<meta property="og:image" content="{{.}}">
218-
<meta property="twitter:image" content="{{.}}">
242+
{{- if (and (gt $og_image_width 0) (gt $og_image_height 0)) -}}
243+
<meta property="og:image:width" content="{{ $og_image_width }}">
244+
<meta property="og:image:height" content="{{ $og_image_height }}">
245+
{{- end -}}
246+
{{- with $og_image_alt -}}
247+
<meta property="og:image:alt" content="{{ . }}">
248+
{{- end -}}
219249
{{- end -}}
220250
<meta property="og:locale" content="{{ site.LanguageCode | default "en-us" }}">
221251
{{ if .IsPage }}

static/img/FORRTbanner.webp

41 KB
Loading

0 commit comments

Comments
 (0)