Hello everyone!
I am stuck with share partial, which works, but I think it can be a little better, at least:
partials/share.html
:
{{ if $share := .Param "share" }}
<div class="share">
{{ range $share }}
{{ range where $.Site.Data.share.items ".id" . }}
{{ $href := replace .url "{{ .Permalink }}" ($.Permalink | htmlEscape) }}
{{ $href = replace $href "{{ .Title }}" ($.Title | htmlEscape) }}
<a class="share-link" href="{{ $href }}" target="_blank" rel="noopener noreferrer">{{ .title }}</a>
{{ end }}
{{ end }}
</div>
{{ end }}
data/share.toml
:
[[items]]
id = "facebook"
title = "Facebook"
url = "https://www.facebook.com/sharer/sharer.php?u={{ .Permalink }}"
[[items]]
id = "twitter"
title = "Twitter"
url = "https://twitter.com/intent/tweet/?url={{ .Permalink }}&text={{ .Title }}"
[[items]]
id = "linkedin"
title = "LinkedIn"
url = "https://www.linkedin.com/shareArticle?mini=true&url={{ .Permalink }}&title={{ .Title }}"
config.toml
:
[Params]
share = ["twitter", "facebook"] # activate share buttons in giver order
I wonder if there is a way to refactor such share partial? Any solutions/ideas?