Skip to content

Commit 4f3e709

Browse files
theme(feat): social media follow links
documentation will follow at https://github.com/theNewDynamic/gohugo-theme-ananke/wiki/Social-media-network-setup Signed-off-by: Patrick Kollitsch <[email protected]>
1 parent c672ad4 commit 4f3e709

File tree

10 files changed

+113
-21
lines changed

10 files changed

+113
-21
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,4 @@ resources/_gen/
3838
.wireit
3939
.favorites.json
4040
*.code-workspace
41+
config/gargulus

assets/ananke/socials/envelope.svg

+1
Loading

config/_default/params.toml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
[ananke.social]
2+
icon_path = "ananke/socials/%s.svg"
3+
4+
[ananke.social.follow]
5+
new_window_icon = false # show a little "opens in new window" icon next to the link
6+
networks = [
7+
"facebook",
8+
"bluesky",
9+
"linkedin"
10+
]
11+
12+
# social media network setups
13+
[[ananke.social.networks]]
14+
slug = "facebook"
15+
label = "Facebook"
16+
profile = "https://www.facebook.com/%s"
17+
icon = "facebook" # font awesome brand icon name
18+
19+
[[ananke.social.networks]]
20+
slug = "bluesky"
21+
label = "Bluesky"
22+
profile = "https://bsky.app/profile/%s"
23+
icon = "bluesky" # font awesome brand icon name
24+
25+
[[ananke.social.networks]]
26+
slug = "linkedin"
27+
label = "LinkedIn"
28+
profile = "http://linkedin.com/in/%s"
29+
icon = "linkedin" # font awesome brand icon name
30+
31+
# optional config parameters
32+
# [[ananke.social.networks]]
33+
# rel = "noopener" # set to noopener by default, could contain `me` and other values

exampleSite/config.toml

+9-3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ description = "The last theme you'll ever need. Maybe."
3838
background_color_class = "bg-black"
3939
recent_posts_number = 3
4040

41-
[[params.ananke_socials]]
42-
name = "twitter"
43-
url = "https://twitter.com/GoHugoIO"
41+
[params.ananke.social]
42+
[params.ananke.social.facebook]
43+
username = "patrick.kollitsch"
44+
45+
[params.ananke.social.linkedin]
46+
username = "patrickkollitsch"
47+
48+
[params.ananke.social.bluesky]
49+
username = "kollitsch.dev"

layouts/partials/site-footer.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
<a class="f4 fw4 hover-white no-underline white-70 dn dib-ns pv2 ph3" href="{{ .Site.Home.Permalink }}" >
44
&copy; {{ with .Site.Copyright | default .Site.Title }} {{ . | safeHTML }} {{ now.Format "2006"}} {{ end }}
55
</a>
6-
<div>{{ partial "social-follow.html" . }}</div>
6+
<div>{{ partialCached "social/follow.html" . }}</div>
77
</div>
88
</footer>

layouts/partials/site-navigation.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
{{ end }}
2121
</ul>
2222
{{ end }}
23-
{{ partialCached "social-follow.html" . }}
23+
{{ partialCached "social/follow.html" . }}
2424
</div>
2525
</div>
2626
</nav>

layouts/partials/social-follow.html

-14
This file was deleted.

layouts/partials/social-share.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
{{ $facebook_href := printf "https://www.facebook.com/sharer.php?u=%s" $url }}
55
{{ $twitter_href := printf "https://twitter.com/intent/tweet?url=%s&text=%s" $url $title }}
6-
{{ with site.Social.twitter }}
6+
{{ with site.Params.Social.twitter }}
77
{{ $twitter_href = printf "%s&via=%s" $twitter_href . }}
88
{{ end }}
99
{{ $linkedin_href := printf "https://www.linkedin.com/shareArticle?mini=true&url=%s&title=%s" $url $title }}

layouts/partials/social/follow.html

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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 -}}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"command": "commit-and-tag-version --sign -a -t \"v\" --releaseCommitMessageFormat \"chore(release): v{{currentTag}}\" --prerelease prerelease -- --no-verify"
5656
},
5757
"server": {
58-
"command": "cd exampleSite; rm -rf public; hugo server -D -E -F --disableFastRender --verbose --logLevel debug --debug --tlsAuto --panicOnWarning"
58+
"command": "cd exampleSite; rm -rf public; hugo server -D -E -F --environment gargulus --disableFastRender --verbose --logLevel debug --debug --tlsAuto --panicOnWarning"
5959
}
6060
}
6161
}

0 commit comments

Comments
 (0)