theme(fix): add labels and label override functionality

Signed-off-by: Patrick Kollitsch <patrick@davids-neighbour.com>
This commit is contained in:
Patrick Kollitsch 2024-10-20 15:58:53 +07:00
parent 9254c455c9
commit 7913086a0f
No known key found for this signature in database
GPG key ID: 5A5360B005AD68C7
4 changed files with 25 additions and 93 deletions

View file

@ -159,85 +159,7 @@ Using front matter and cascade, this can be customized for a whole section, or j
### Social Follow + Share ### Social Follow + Share
The theme automatically adds "Follow" link icons to the header and footer and "Share" link icons to pages unless `disable_share` parameter is set to true either on the site level (site params) or page level (front matter). Each built-in services sports a label, an icon and a color. Read the documentation for [social follow](https://github.com/theNewDynamic/gohugo-theme-ananke/wiki/Social-media-network-setup#configure-social-media-follow-links) and [social share](https://github.com/theNewDynamic/gohugo-theme-ananke/wiki/Social-media-network-setup#configure-social-media-follow-links) in our wiki.
In order to register a service to be used, user must add an `ananke_socials` parameter to its project configuration file and list them through it in the desired order. Each entry must bear a
- name*: It matches the built-in service reference (Ex: twitter, github)
- url*: The url of the handle's profile on the service (Ex: <https://twitter.com/theNewDynamic>, <https://github.com/>
theNewDynamic)
- rel: (default: `noopener`) Controls the `rel` attribute of the "follow" link. Useful for Mastodon verification which requires a `rel="me"` on the link.
```yaml
params:
ananke_socials:
- name: twitter
url: https://twitter.com/theNewDynamic
- name: github
url: https://github.com/theNewDynamic
- name: mastodon
url: https://social.example.com/@username
rel: me noopener
```
If user needs to overwrite default `color` and `label` of the service, they simply need to append the following to the entry:
- label: The displayed name of the service to be used to popuplate `[title]` attributes and read-only. (Ex: Twitter, GitHub)
- color: Used for styling purposes. (Ex: '#1da1f2', '#6cc644')
```yaml
params:
ananke_socials:
- name: twitter
url: https://twitter.com/theNewDynamic
label: TND Twitter
- name: github
url: https://github.com/theNewDynamic
label: TND GitHub Account
color: '#ff6800'
```
#### Limit Follow or Share
If a user needs to control Share and Follow of a service, for example enabling "Share on Facebook" without having a Facebook Page to "follow", they can set `follow: false` one the registered service.
```yaml
params:
ananke_socials:
- name: facebook
label: Facebook
follow: false
- name: twitter
url: https://twitter.com/theNewDynamic
label: TND Twitter
```
#### Social Icons Customization
On top of easily customizing the built-in services' label and color, user can overwrite their icon by adding an svg file at `/assets/ananke/socials` with a filename matching the service's name.
For example, in order to use your own GitHub icon, simply add an svg file at `/assets/ananke/socials/github.svg`
#### Built-in Services
Here is the list of built-in services. Those marked with an `*` are also part of the "Share" module.
- twitter*
- instagram
- youtube
- github
- gitlab
- keybase
- linkedin*
- medium
- mastodon
- slack
- stackoverflow
- facebook*
- rss
#### Complement
In order to add an unkown service (absent from the list above), you simply need to add all three settings to `ananke_socials`: name, url, label, color, and optionally add an icon file matching the `name` to the `assets/ananke/socials` directory. In the absence of an icon, the theme will print the service's label.
### Content indexing ### Content indexing

View file

@ -1,75 +1,83 @@
[ananke.social] [ananke.social]
icon_path = "ananke/socials/%s.svg" icon_path = "ananke/socials/%s.svg"
# [ananke.social.follow] [ananke.social.follow]
# new_window_icon = false # show a little "opens in new window" icon next to the link new_window_icon = false # show a little "opens in new window" icon next to the link
# networks = [ networks = [
# "facebook", "facebook",
# "bluesky", "bluesky",
# "linkedin" "linkedin"
# ] ]
# social media network setups # social media network setups
[[ananke.social.networks]] [[ananke.social.networks]]
slug = "bluesky" slug = "bluesky"
label = "Bluesky"
profile = "https://bsky.app/profile/%s" profile = "https://bsky.app/profile/%s"
icon = "bluesky" # font awesome brand icon name icon = "bluesky" # font awesome brand icon name
[[ananke.social.networks]] [[ananke.social.networks]]
slug = "email" slug = "email"
label = "Email"
profile = false profile = false
icon = "envelope" # font awesome free icon name icon = "envelope" # font awesome free icon name
[[ananke.social.networks]] [[ananke.social.networks]]
slug = "facebook" slug = "facebook"
label = "Facebook"
profile = "https://www.facebook.com/%s" profile = "https://www.facebook.com/%s"
icon = "facebook" # font awesome brand icon name icon = "facebook" # font awesome brand icon name
[[ananke.social.networks]] [[ananke.social.networks]]
slug = "hackernews" slug = "hackernews"
label = "Hacker News"
profile = "https://news.ycombinator.com/user?id=%s" profile = "https://news.ycombinator.com/user?id=%s"
icon = "hacker-news" # font awesome brand icon name icon = "hacker-news" # font awesome brand icon name
[[ananke.social.networks]] [[ananke.social.networks]]
slug = "linkedin" slug = "linkedin"
label = "LinkedIn"
profile = "http://linkedin.com/in/%s" profile = "http://linkedin.com/in/%s"
icon = "linkedin" # font awesome brand icon name icon = "linkedin" # font awesome brand icon name
[[ananke.social.networks]] [[ananke.social.networks]]
slug = "pinterest" slug = "pinterest"
label = "Pinterest"
profile = "https://www.pinterest.com/%s/" profile = "https://www.pinterest.com/%s/"
icon = "pinterest" # font awesome brand icon name icon = "pinterest" # font awesome brand icon name
[[ananke.social.networks]] [[ananke.social.networks]]
slug = "reddit" slug = "reddit"
label = "Reddit"
profile = "https://www.reddit.com/user/%s/" profile = "https://www.reddit.com/user/%s/"
icon = "reddit" # font awesome brand icon name icon = "reddit" # font awesome brand icon name
[[ananke.social.networks]] [[ananke.social.networks]]
slug = "telegram" slug = "telegram"
label = "Telegram"
profile = "https://t.me/%s" profile = "https://t.me/%s"
icon = "telegram" # font awesome brand icon name icon = "telegram" # font awesome brand icon name
[[ananke.social.networks]] [[ananke.social.networks]]
slug = "tumblr" slug = "tumblr"
label = "Tumblr"
profile = "https://www.tumblr.com/blog/%s" profile = "https://www.tumblr.com/blog/%s"
icon = "tumblr" # font awesome brand icon name icon = "tumblr" # font awesome brand icon name
[[ananke.social.networks]] [[ananke.social.networks]]
slug = "twitter" slug = "twitter"
label = "Twitter"
profile = "https://twitter.com/%s" profile = "https://twitter.com/%s"
icon = "twitter" # font awesome brand icon name icon = "twitter" # font awesome brand icon name
[[ananke.social.networks]] [[ananke.social.networks]]
slug = "whatsapp" slug = "whatsapp"
label = "WhatsApp"
profile = false profile = false
icon = "whatsapp" # font awesome brand icon name icon = "whatsapp" # font awesome brand icon name
[[ananke.social.networks]] [[ananke.social.networks]]
slug = "xing" slug = "xing"
label = "Xing"
profile = "https://www.xing.com/profile/%s" profile = "https://www.xing.com/profile/%s"
icon = "xing" # font awesome brand icon name icon = "xing" # font awesome brand icon name
# optional config parameters
# [[ananke.social.networks]]
# rel = "noopener" # set to noopener by default, could contain `me` and other values

View file

@ -49,6 +49,7 @@ networks = [
[params.ananke.social] [params.ananke.social]
[params.ananke.social.facebook] [params.ananke.social.facebook]
username = "patrick.kollitsch" username = "patrick.kollitsch"
# profilelink = "https://www.facebook.com/patrick.kollitsch"
[params.ananke.social.linkedin] [params.ananke.social.linkedin]
username = "patrickkollitsch" username = "patrickkollitsch"

View file

@ -14,6 +14,7 @@
{{- $network := $setup.slug -}} {{- $network := $setup.slug -}}
{{- $profile := index $config $network -}} {{- $profile := index $config $network -}}
{{- $rel := $setup.rel | default "noopener" -}} {{- $rel := $setup.rel | default "noopener" -}}
{{- $label := $profile.label | default $setup.label -}}
{{- $link := (printf $setup.profile $profile.username) -}} {{- $link := (printf $setup.profile $profile.username) -}}
{{- with $profile.profilelink -}} {{- with $profile.profilelink -}}
@ -23,8 +24,8 @@
{{- $languageDirection := cond (eq $.Site.Language.LanguageDirection "rtl") "ml1" "mr1" -}} {{- $languageDirection := cond (eq $.Site.Language.LanguageDirection "rtl") "ml1" "mr1" -}}
<a href="{{ $link }}" target="_blank" rel="{{ $rel }}" <a href="{{ $link }}" target="_blank" rel="{{ $rel }}"
class="{{ .name }} ananke-social-link link-transition stackoverflow link dib z-999 pt3 pt0-l {{ $languageDirection }}" class="{{ .name }} ananke-social-link link-transition stackoverflow link dib z-999 pt3 pt0-l {{ $languageDirection }}"
title="follow on {{ .label }} - Opens in a new window" title="follow on {{ $label }} - Opens in a new window"
aria-label="follow on {{ .label }} - Opens in a new window"> aria-label="follow on {{ $label }} - Opens in a new window">
{{- with .icon -}} {{- with .icon -}}
{{- $icon := resources.Get (printf "ananke/socials/%s.svg" .) -}} {{- $icon := resources.Get (printf "ananke/socials/%s.svg" .) -}}
{{- with $icon -}} {{- with $icon -}}
@ -34,7 +35,7 @@
</span> </span>
{{- end -}} {{- end -}}
{{- else -}} {{- else -}}
{{- .label -}} {{- $label -}}
{{- end -}} {{- end -}}
{{- with $config.follow.new_window_icon -}} {{- with $config.follow.new_window_icon -}}
{{- partial "new-window-icon.html" . -}} {{- partial "new-window-icon.html" . -}}