mirror of https://github.com/theNewDynamic/gohugo-theme-ananke.git

Regis Philibert
02.22.2021 c7b9901e01ec3720b47fcef3d33bdbd6ce53f000
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
{{/*
  socials/GetRegisteredServices
  Retrieves the list of user registered services.
  Support legacy settings (root of params with service name as key)
 
  @author @regisphilibert
 
  @context Any (.)
 
  @access private
 
  @returns Slice of Maps
    - String (.name)
      String (.url)
      String (.label)?
      String (.color)?
 
*/}}
 
{{ $registered_services := slice }}
{{/* We first look for legacy settings that lives at the root of the site.Params as such (github: https://github.com/
theNewDynamic) and them to the list with key as .name and value as .url */}}
{{ $user_using_legacy := false }}
 
{{ $legacy_api_services := slice "facebook" "twitter" "instagram" "youtube" "github" "gitlab" "keybase" "linkedin" "medium" "mastodon" "slack" "stackoverflow" "rss" }}
{{ range $name := $legacy_api_services }}
  {{ with $url := index site.Params . }}
    {{/* If we can find a parameter matching the key with a set value, we add it with proper name and url */}}
    {{/* We also note that user is using legacy for potential potential deprecation warnings */}}
    {{ $user_using_legacy = true }}
    {{ $registered_services = $registered_services | append (dict "name" $name "url" $url) }}
  {{ end }}
{{ end }}
 
{{/* Then we go through the current way of registering services as per referenced in README */}}
{{ with site.Params.ananke_socials }}
  {{ range $service := . }}
    {{/* Only if the service has a .name, we add it all its keys to the slice of registered services */}}
    {{ with .name }}
      {{ $registered_services = $registered_services | append $service }}
    {{ end }}
  {{ end }}
{{ end }}
 
{{ return $registered_services }}