From e99eb347955c625972a0dfe86cf6ffe1b8524341 Mon Sep 17 00:00:00 2001 From: Christian Olsen <9137189+Chrede88@users.noreply.github.com> Date: Thu, 24 Dec 2020 06:15:26 -0800 Subject: [PATCH] feat: add option to show superuser social links in header (#2010) To use, add label and display options to superuser's `social` links: ``` social: - icon: twitter icon_pack: fab link: https://twitter.com/ label: Follow me on Twitter display: header: true ``` --- .../partials/functions/get_social_link.html | 37 +++++++++++++++++++ wowchemy/layouts/partials/navbar.html | 13 +++++++ 2 files changed, 50 insertions(+) create mode 100644 wowchemy/layouts/partials/functions/get_social_link.html diff --git a/wowchemy/layouts/partials/functions/get_social_link.html b/wowchemy/layouts/partials/functions/get_social_link.html new file mode 100644 index 00000000..a6b3ae22 --- /dev/null +++ b/wowchemy/layouts/partials/functions/get_social_link.html @@ -0,0 +1,37 @@ +{{/* Function to return a linked social icon as a map from an iteration of an author's `social` data. */}} + +{{ $scr := newScratch }} + +{{/* Get icon name. */}} +{{ $scr.SetInMap "social_link" "icon" .icon }} + +{{/* Get icon pack (default to Font Awesome's Solid pack). */}} +{{ $pack := or .icon_pack "fas" }} +{{ $scr.SetInMap "social_link" "icon_pack" $pack }} + +{{/* Derive Font Awesome class name prefix. */}} +{{ $pack_prefix := $pack }} +{{ if in (slice "fab" "fas" "far" "fal") $pack }} + {{ $pack_prefix = "fa" }} +{{ end }} +{{ $scr.SetInMap "social_link" "pack_prefix" $pack_prefix }} + +{{/* Get tooltip label (default to none). */}} +{{ $scr.SetInMap "social_link" "tooltip" (.label | default "") }} + +{{/* Get screen reader label (default to icon name). */}} +{{ $scr.SetInMap "social_link" "aria_label" (.label | default .icon) }} + +{{/* Get external link or relative internal link. */}} +{{ $link := .link }} +{{ $target := "" }} +{{ $scheme := (urls.Parse $link).Scheme }} +{{ if not $scheme }} + {{ $link = .link | relLangURL }} +{{ else if in (slice "http" "https") $scheme }} + {{ $target = "target=\"_blank\" rel=\"noopener\"" }} +{{ end }} +{{ $scr.SetInMap "social_link" "link" $link }} +{{ $scr.SetInMap "social_link" "target" $target }} + +{{ return $scr.Get "social_link" }} diff --git a/wowchemy/layouts/partials/navbar.html b/wowchemy/layouts/partials/navbar.html index db72a756..34a3e418 100644 --- a/wowchemy/layouts/partials/navbar.html +++ b/wowchemy/layouts/partials/navbar.html @@ -139,6 +139,19 @@