From 70fff82b5a98038c78a797360c5048b3e0a8e0e2 Mon Sep 17 00:00:00 2001 From: Patrick Kollitsch Date: Tue, 8 Feb 2022 21:20:40 +0700 Subject: [PATCH] feat: sort networks by order in the configuration slice see #16 --- layouts/partials/func/sortNetworks.html | 13 +++++++++++++ layouts/partials/widgets/share-buttons.html | 13 ++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) create mode 100644 layouts/partials/func/sortNetworks.html diff --git a/layouts/partials/func/sortNetworks.html b/layouts/partials/func/sortNetworks.html new file mode 100644 index 0000000..31034af --- /dev/null +++ b/layouts/partials/func/sortNetworks.html @@ -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 -}} diff --git a/layouts/partials/widgets/share-buttons.html b/layouts/partials/widgets/share-buttons.html index 1ff9888..3b56ec5 100644 --- a/layouts/partials/widgets/share-buttons.html +++ b/layouts/partials/widgets/share-buttons.html @@ -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) -}}
{{- range $network, $setup := $setups -}}