get_social_link.html 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. {{/* Function to return a linked social icon as a map from an iteration of an author's `social` data. */}}
  2. {{ $scr := newScratch }}
  3. {{/* Get icon name. */}}
  4. {{ $scr.SetInMap "social_link" "icon" .icon }}
  5. {{/* Get icon pack (default to Font Awesome's Solid pack). */}}
  6. {{ $pack := or .icon_pack "fas" }}
  7. {{ $scr.SetInMap "social_link" "icon_pack" $pack }}
  8. {{/* Derive Font Awesome class name prefix. */}}
  9. {{ $pack_prefix := $pack }}
  10. {{ if in (slice "fab" "fas" "far" "fal") $pack }}
  11. {{ $pack_prefix = "fa" }}
  12. {{ end }}
  13. {{ $scr.SetInMap "social_link" "pack_prefix" $pack_prefix }}
  14. {{/* Get tooltip label (default to none). */}}
  15. {{ $scr.SetInMap "social_link" "tooltip" (.label | default "") }}
  16. {{/* Get screen reader label (default to icon name). */}}
  17. {{ $scr.SetInMap "social_link" "aria_label" (.label | default .icon) }}
  18. {{/* Get external link or relative internal link. */}}
  19. {{ $link := .link }}
  20. {{ $target := "" }}
  21. {{ $scheme := (urls.Parse $link).Scheme }}
  22. {{ if not $scheme }}
  23. {{ $link = .link | relLangURL }}
  24. {{ else if in (slice "http" "https") $scheme }}
  25. {{ $target = "target=\"_blank\" rel=\"noopener\"" }}
  26. {{ end }}
  27. {{ $scr.SetInMap "social_link" "link" $link }}
  28. {{ $scr.SetInMap "social_link" "target" $target }}
  29. {{ return $scr.Get "social_link" }}