|
| 1 | +{{- $context := . -}} |
| 2 | + |
| 3 | +{{- $config := site.Params.ananke.social -}} |
| 4 | +{{- $networks := $config.follow.networks -}} |
| 5 | +{{- $setups := (collections.Where $config.networks "slug" "in" $networks) -}} |
| 6 | +{{/* This here is an ugly workaround for GoHugo's missing sortByArray feature. |
| 7 | + Let's cache it so it does not take away too much time. |
| 8 | + PS: It's also a couple of years old, so maybe there is a better solution by now. */}} |
| 9 | +{{- $setups = partials.IncludeCached "func/sortNetworks.html" (dict "networks" $networks "setups" $setups) "social-follow" -}} |
| 10 | + |
| 11 | +<div class="ananke-socials"> |
| 12 | + {{- range $setups -}} |
| 13 | + {{- $setup := . -}} |
| 14 | + {{- $network := $setup.slug -}} |
| 15 | + {{- $profile := index $config $network -}} |
| 16 | + {{- $rel := $setup.rel | default "noopener" -}} |
| 17 | + {{- $link := (printf $setup.profile $profile.username) -}} |
| 18 | + {{- $languageDirection := cond (eq $.Site.Language.LanguageDirection "rtl") "ml1" "mr1" -}} |
| 19 | + <a href="{{ $link }}" target="_blank" rel="{{ $rel }}" |
| 20 | + class="{{ .name }} ananke-social-link link-transition stackoverflow link dib z-999 pt3 pt0-l {{ $languageDirection }}" |
| 21 | + title="follow on {{ .label }} - Opens in a new window" |
| 22 | + aria-label="follow on {{ .label }} - Opens in a new window"> |
| 23 | + {{- with .icon -}} |
| 24 | + {{- $icon := resources.Get (printf "ananke/socials/%s.svg" .) -}} |
| 25 | + {{- with $icon -}} |
| 26 | + <span class="icon"> |
| 27 | + {{ .Content | safeHTML }} |
| 28 | + {{/* @todo indicator for missing or misconfigured icon */}} |
| 29 | + </span> |
| 30 | + {{- end -}} |
| 31 | + {{- else -}} |
| 32 | + {{- .label -}} |
| 33 | + {{- end -}} |
| 34 | + {{- with $config.follow.new_window_icon -}} |
| 35 | + {{- partial "new-window-icon.html" . -}} |
| 36 | + {{- end -}} |
| 37 | + </a> |
| 38 | + {{- end -}} |
| 39 | +</div> |
| 40 | + |
| 41 | +{{ define "partials/func/sortNetworks.html" }} |
| 42 | + {{- /* |
| 43 | + |
| 44 | + Sorting a list of social networks defined by the order in `networks`. |
| 45 | + Only networks present in both `networks` and `setups` will be included. Items missing from `networks` are ignored. |
| 46 | + Use `networks` to setup the order of the networks and which network to enable. |
| 47 | + |
| 48 | + Usage: {{ $setups = partials.IncludeCached "func/sortNetworks.html" (dict "networks" $networks "setups" $setups) }} |
| 49 | + |
| 50 | + See also `config/_default/params.toml` > `ananke.social` for details. |
| 51 | + |
| 52 | + */ -}} |
| 53 | + {{- $networks := .networks -}} |
| 54 | + {{- $setups := .setups -}} |
| 55 | + {{- $output := collections.Slice -}} |
| 56 | + {{- range $networks -}} |
| 57 | + {{- $network := . -}} |
| 58 | + {{- range $setups -}} |
| 59 | + {{- if compare.Eq .slug $network -}} |
| 60 | + {{- $output = $output | collections.Append . -}} |
| 61 | + {{- end -}} |
| 62 | + {{- end -}} |
| 63 | + {{- end -}} |
| 64 | + {{- return $output -}} |
| 65 | +{{- end -}} |
0 commit comments