Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Commit

Permalink
feat: sort networks by order in the configuration slice
Browse files Browse the repository at this point in the history
see #16
  • Loading branch information
davidsneighbour committed Feb 8, 2022
1 parent b876406 commit 70fff82
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
13 changes: 13 additions & 0 deletions layouts/partials/func/sortNetworks.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{- $networks := .networks -}}
{{- $setups := .setups -}}

{{- $output := slice -}}
{{- range $networks -}}
{{- $network := . -}}
{{- range $setups -}}
{{- if eq .slug $network -}}
{{- $output = $output | append . -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- return $output -}}
13 changes: 8 additions & 5 deletions layouts/partials/widgets/share-buttons.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
{{- $context := . -}}

{{ $networks := slice }}
{{ with site.Params.dnb.social.sharebuttons.networks }}
{{ $networks = . }}
{{ end }}
{{ $setups := (where site.Data.dnb.social.shares.items "slug" "in" $networks)}}
{{- $networks := slice -}}
{{- with site.Params.dnb.social.sharebuttons.networks -}}
{{- $networks = . -}}
{{- end -}}
{{- $setups := (where site.Data.dnb.social.shares.items "slug" "in" $networks) -}}
{{- /* This here is an ugly workaround for Hugo's missing sortByArray feature.
Cache it so it does not take away too much time. */ -}}
{{- $setups = partialCached "func/sortNetworks.html" (dict "networks" $networks "setups" $setups) -}}

<div class="is--sharebuttons">
{{- range $network, $setup := $setups -}}
Expand Down

0 comments on commit 70fff82

Please sign in to comment.