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

Commit

Permalink
feat: add share buttons
Browse files Browse the repository at this point in the history
see #16
  • Loading branch information
davidsneighbour committed Feb 7, 2022
1 parent ffe597c commit 4867182
Show file tree
Hide file tree
Showing 5 changed files with 235 additions and 2 deletions.
20 changes: 18 additions & 2 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@ extended = false
min = "0.84.0"

[[module.mounts]]
source = "layouts"
target = "layouts"
source = "data"
target = "data"

[[module.mounts]]
source = "i18n"
target = "i18n"

[[module.mounts]]
source = "layouts"
target = "layouts"

[[module.imports]]
disable = false
ignoreConfig = false
Expand All @@ -24,3 +28,15 @@ disable = false
ignoreConfig = false
ignoreImports = false
path = "github.com/dnb-org/dnb-hugo-debug"

[[module.imports]]
disable = false
ignoreConfig = false
ignoreImports = false
path = "github.com/dnb-org/dnb-hugo-icons"

[params.dnb.social]
[params.dnb.social.sharebuttons]
icons = true
sharetext = true
networks = ["facebook", "twitter", "linkedin"]
89 changes: 89 additions & 0 deletions data/dnb/social/shares.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
[items.facebook]
link = "https://facebook.com/sharer/sharer.php"
icon = "facebook"
[items.facebook.particles]
u = "permalink"

[items.twitter]
link = "https://twitter.com/intent/tweet/"
icon = "twitter"
[items.twitter.particles]
text = "description"
url = "permalink"

[items.tumblr]
link = "https://www.tumblr.com/widgets/share/tool"
[items.tumblr.particles]
canonicalUrl = "permalink"
shareSource = "source"
title = "title"
caption = "description"
content = "description"
params = "posttype=link"

[items.email]
link = "mailto:"
icon = "envelope"
[items.email.particles]
body = "permalink"
subject = "title"

[items.pinterest]
link = "https://pinterest.com/pin/create/button/"
icon = "pinterest"
[items.pinterest.particles]
url = "permalink"
media = "permalink"
description = "description"

[items.linkedin]
link = "https://www.linkedin.com/shareArticle"
icon = "linkedin"
[items.linkedin.particles]
url = "permalink"
title = "title"
summary = "description"
source = "permalink"
params = "mini=true"

[items.reddit]
link = "https://reddit.com/submit/"
icon = "reddit"
[items.reddit.particles]
url = "permalink"
title = "title"
params = "resubmit=true"

[items.xing]
link = "https://www.xing.com/app/user"
separator = ";"
[items.xing.particles]
url = "permalink"
title = "title"
params = "op=share"

[items.whatsapp]
link = "whatsapp://send"
linkintext = true
icon = "whatsapp"
[items.whatsapp.particles]
text = "description"

[items.hackernews]
link = "https://news.ycombinator.com/submitlink"
[items.hackernews.particles]
u = "permalink"
t = "description"

[items.vkontakte]
link = "http://vk.com/share.php"
[items.vkontakte.particles]
title = "title"
url = "permalink"

[items.telegram]
link = "https://telegram.me/share/url"
icon = "telegram"
[items.telegram.particles]
text = "description"
url = "permalink"
36 changes: 36 additions & 0 deletions i18n/de.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,39 @@ other = "Auf LinkedIn teilen"

[socialmedia_sidebar]
other = "Social Media"

[share_on_facebook]
other = "Share on Facebook"

[share_on_twitter]
other = "Share on Twitter"

[share_on_tumblr]
other = "Share on Tumblr"

[share_on_email]
other = "Share by E-Mail"

[share_on_pinterest]
other = "Share on Pinterest"

[share_on_linkedin]
other = "Share on LinkedIn"

[share_on_reddit]
other = "Share on Reddit"

[share_on_xing]
other = "Share on XING"

[share_on_whatsapp]
other = "Share on WhatsApp"

[share_on_hackernews]
other = "Share on Hacker News"

[share_on_vkontakte]
other = "Share on VK"

[share_on_telegram]
other = "Share on Telegram"
36 changes: 36 additions & 0 deletions i18n/en.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,39 @@ other = "Share on LinkedIn"

[socialmedia_sidebar]
other = "Social Media"

[share_on_facebook]
other = "Share on Facebook"

[share_on_twitter]
other = "Share on Twitter"

[share_on_tumblr]
other = "Share on Tumblr"

[share_on_email]
other = "Share by E-Mail"

[share_on_pinterest]
other = "Share on Pinterest"

[share_on_linkedin]
other = "Share on LinkedIn"

[share_on_reddit]
other = "Share on Reddit"

[share_on_xing]
other = "Share on XING"

[share_on_whatsapp]
other = "Share on WhatsApp"

[share_on_hackernews]
other = "Share on Hacker News"

[share_on_vkontakte]
other = "Share on VK"

[share_on_telegram]
other = "Share on Telegram"
56 changes: 56 additions & 0 deletions layouts/partials/widgets/share-buttons.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{{- $context := . -}}

{{ $networks := slice }}
{{ with site.Params.dnb.social.sharebuttons.networks }}
{{ $networks = . }}
{{ end }}

{{ $setups := site.Data.dnb.social.shares.items}}
{{/*
{{ $setups := $setups | intersect (where $setup in $networks) }} */}}


<div class="is--sharebuttons">
{{- range $network, $setup := $setups -}}
{{- $separator := "&" -}}
{{ $icon := false }}
{{ with $setup.icon }}
{{- $icon = . -}}
{{ end }}
{{- $title := $context.Title | htmlEscape -}}
{{- $description := $context.Summary | htmlEscape -}}
{{- $permalink := $context.Permalink | htmlEscape -}}
{{- with $setup.separator -}}
{{- $separator = . -}}
{{- end -}}
{{- $link := printf "%s%s" $setup.link "?" -}}
{{- range $key, $value := $setup.particles -}}
{{- if eq $key "params" -}}
{{- $link = printf "%s%s%s" $permalink $separator $value -}}
{{- else -}}
{{- if eq $value "description" -}}
{{- $link = printf "%s%s%s=%s" $link $separator $key $description -}}
{{- else if eq $value "title" -}}
{{- $link = printf "%s%s%s=%s" $link $separator $key $title -}}
{{- else if eq $value "permalink" -}}
{{- $link = printf "%s%s%s=%s" $link $separator $key $permalink -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $sharetext := i18n (printf "share_on_%s" $network) -}}
<a class="is--sharebutton"
href="{{- $link -}}"
target="_blank"
rel="noopener"
aria-label="{{- $sharetext -}}">
{{- with site.Params.dnb.social.sharebuttons.icons -}}
<span aria-hidden="true" class="icon">
{{- partialCached "bsicon.html" $icon $icon -}}
</span>
{{- end -}}
{{- with site.Params.dnb.social.sharebuttons.sharetext -}}
{{- $sharetext -}}
{{- end -}}
</a>
{{- end -}}
</div>

0 comments on commit 4867182

Please sign in to comment.